简体   繁体   English

从应用程序全局变量调用时,线程的 WaitForSingleObject 会冻结

[英]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.我创建了一个线程作为某个池的一部分,当应用程序(实际上是 DLL)完成时需要销毁该线程。 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.所以我有一些“全局变量”,意思是一个静态全局实例化的结构,在析构函数中它释放任何创建的线程并使用 WaitForSingleObject 等待它们。 Unfortunately this freezes forever and checking in the debugger reveals that the threads are still there, just stuck somewhere in the system DLLs.不幸的是,这永远冻结了,并且在调试器中检查发现线程仍然存在,只是卡在系统 DLL 的某个地方。 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.我在 Win32 文档中没有看到任何提及。 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.所以解决方案确实是避免等待,实际上释放 DllMain 中的任何内容(包括全局变量)都是不好的,因此需要在此之前释放所有重要的内容。 That's sometimes a bit tricky, when it comes to DLLs, but well...当涉及到 DLL 时,这有时有点棘手,但是……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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