John M. Dlugosz
On 9/14/2011 4:48 PM, Christopher Pisz wrote:
I've googled for a few hours and seen people mention something to the
of "you cannot call join from DllMain" and "while DLL is unloading", but no explanation or alternative.
How would I go about fixing this problem? I don't think I can guarentee noone will ever make a global instance of my class....
As I recall, the DLLMain's as well as process startup code in the main EXE is called with a process mutex, so threads cannot be started until the normal main is called. Likewise at shut-down, but I don't know what happens to other threads. I suspect
before the unloading process begins. Once your main() returns, at some
effect they are halted point threads are
halted so ensure that threading is done before that!
I assume you mean the DLL is unloading because the process is terminating. I don't know if that's still the case for dynamic LoadLibrary.
Yes, at process terminatation, the dll gets unloaded, which calls a constructor, which attempts to join a thread in a class that has created a thread with its constructor. I get deadlock. I did some reading on MSDN and it seems there are severe restrictions on what can be done at dll load and unload time. So, I think the solution is to implement a c-style init() and shutdown() methods for the DLL to take care of any resources it has internally.