std::thread increses DLL reference count, which prevents the unloading of the DLL

北城以北 提交于 2021-01-29 04:35:01

问题


I have a windows c++ dll which gets loaded by a third party program. I recently added a thread pool (this one https://github.com/progschj/ThreadPool/blob/master/ThreadPool.h).

But now the dll get no longer unloaded when the third party program no longer needs it. The reason is that every thread spawned in the thread pool increases the dll reference count by one. One problem is that I don't know when the third party program no longer needs the dll, so I can't manually shutdown the thread pool before, to reduce the reference count.

So my question is, is there a way to create a thread without increasing the dll's reference count? And if so, when the dll gets unloaded do I need to manually shut down the thread pool ?

Side note: I use vs 2019 and c++17.


回答1:


And what about DLL_PROCESS_DETACH does it called? If so you should join threads in it.



来源:https://stackoverflow.com/questions/62397093/stdthread-increses-dll-reference-count-which-prevents-the-unloading-of-the-dl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!