简体   繁体   中英

WaitForSingleObject for a thread freezes when called from application globals

I create a thread as a part of some pool, that needs to be destroyed when the application (DLL actually) finishes. So I have a some "globals", meaning a structure instantiated globally statically and in the destructor it releases any created threads and waits for them using WaitForSingleObject. Unfortunately this freezes forever and checking in the debugger reveals that the threads are still there, just stuck somewhere in the system DLLs. When I call this before the globals are getting released, then all goes fine. I don't see any mentioning of this in the Win32 docs. Any ideas?

So the solution is indeed to avoid waiting and actually releasing anything in the DllMain (including the globals) is bad, so one needs to release everything important before. That's sometimes a bit tricky, when it comes to DLLs, but well...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM