The Current Thread Is Doing A Wait Operating On A Thread Handle In DLL Main

Application Verifier stop message

Handle violation detected. The current thread is doing a wait operation on a thread handle in DllMain.

Probable cause

This stop is generated when the current thread is running code inside the DllMain function of one of the DLLs loaded in the process and it calls WaitForSingleObject or WaitForMultipleObjects to wait on a thread handle in the same process.

This will likely lead to a deadlock because the thread handle will not get signaled unless that second thread is exiting. When the second thread calls ExitThread it will try to acquire the DLL loader lock then call DllMain (DLL_THREAD_DETACH) for all DLLs in the current process. But the loader lock is owned by the first thread (the one that is waiting on the thread handle) so the two threads will deadlock.

Information displayed by Application Verifier in Tool Window

Handle - Handle value

Description – The current thread is doing a wait operation on a thread handle in DllMain

Additional Info - Handle to the thread being waited <handle>

Additional information

The current call stack will show where a wait operation is being performed in DllMain. Frequency of this error is low.

See Also

Concepts

Handle Verifier