I have this dll that gets loaded. We can call it DLL A. DLL A loads another DLL called DLL B. DLL B upon construction creates a thread that does some stuff. At some point DLL A hits the destructor, which calls FreeLibrary on DLL B. So inside the destructor for DLL B it does some cleanup, including a line that is givng me a problem found by AppVerifier.
WaitForSingleObject(thread, amount of time);
I am waiting for the thread I constructed in B to finish processing before closing the handle to it.
Applcation Verifier says this could be causing a deadlock.
This stop is generated when the current thread is currently running code inside the DllMain function of one of the DLLs loaded in the current process and it calls WaitForSingleObject or WaitForMultipleObjects to wait on a thread handle in the same process.
This will most 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.
This is just a probable cause, and I don't even understand it. Does there seem to be anything wrong with my logic?