std :: thread增加DLL引用计数,从而防止DLL的卸载 [英] std::thread increses DLL reference count, which prevents the unloading of the DLL

查看:95
本文介绍了std :: thread增加DLL引用计数,从而防止DLL的卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows c ++ dll,该文件由第三方程序加载.我最近添加了一个线程池(这个 https://github.com/progschj/ThreadPool/blob/master/ThreadPool.h ).

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).

但是,当第三方程序不再需要该dll时,该dll将不再被卸载.原因是线程池中产生的每个线程都会将dll引用计数增加一.一个问题是我不知道第三方程序何时不再需要该dll,因此我之前无法手动关闭线程池以减少引用计数.

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.

所以我的问题是,有没有一种方法可以创建一个线程而不增加dll的引用计数?如果是这样,当dll卸载时,我需要手动关闭线程池吗?

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 ?

旁注:我使用vs 2019和c ++ 17.

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

推荐答案

它调用的DLL_PROCESS_DETACH呢?如果是这样,您应该在其中加入线程.

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

这篇关于std :: thread增加DLL引用计数,从而防止DLL的卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆