问题
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