BUG: Registry access from multiple threads might fail (176906)
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API), when used with:
- the operating system: Microsoft Windows NT 4.0
- the operating system: Microsoft Windows 2000
This article was previously published under Q176906 SYMPTOMS
If you simultaneously access the same registry key from multiple threads in
a single process, an error might occur. For example, if several threads in
a carefully designed multi-threaded Win32 application try to open the same
registry key using RegOpenKeyEx()in a loop, the function could fail with
the following error code of 6:
ERROR_INVALID_HANDLE
This error does not occur across process boundaries. Thus, two single-
threaded processes that are competing for the same registry key will not be
affected by this bug.
CAUSE
This behavior is intermittent and is the result of a race condition between
the threads simultaneously accessing the same registry key.
RESOLUTION
There are several possible workarounds for this situation:
- Do not access the same registry location from multiple threads in a
single process.
- Synchronize access to the registry location. You can do this by
serializing access to the code that accesses the registry with a
critical section or other Win32 synchronization mechanisms.
- When this error occurs, Sleep() a short time and try to access the
registry key again. It is a race condition that causes this problem, so
this workaround is not guaranteed to work. It is possible that the
registry key is indeed invalid. However, this is the easiest solution to
work into an existing application.
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
Modification Type: | Major | Last Reviewed: | 7/6/2004 |
---|
Keywords: | kbAPI kbbug kberrmsg kbKernBase kbpending kbRegistry KB176906 |
---|
|