c++ - QThreadPool maxThreadCount 在应用程序和 DLL 中不同

标签 c++ multithreading qt dll threadpool

在应用程序中使用 QThreadPool::globalInstance() 时,我可以将最大线程数设置为一个数字(例如本例中的 50)

QThreadPool::globalInstance()->setMaxThreadCount(50);

稍后我们可以在同一个应用程序中查询,将返回 50。但是,如果从同一个应用程序调用的 DLL 中查询 QThreadPool::maxThreadCount(),它会返回最大线程数仅为 12。然后我可以将库中的 maxThreadCount 增加到我想要的任何数字,单独来自应用程序的 maxThreadCount 数。

那么 QThreadPool::globalInstance 是否仅对独立应用程序和库具有某种全局性?为什么共享同一进程的 Qt DLL 和应用程序不具有相同的全局 QThreadPool?

最佳答案

查看 QThreadPool 的实现 https://code.woboq.org/qt5/qtbase/src/corelib/global/qglobalstatic.h.html#158 我们可以看到:

QThreadPool *QThreadPool::globalInstance()
    {
        return theInstance();
    }

这里定义https://code.woboq.org/qt5/qtbase/src/corelib/thread/qthreadpool.cpp.html#50

 Q_GLOBAL_STATIC(QThreadPool, theInstance)

从这里开始,如果由于某些不明原因你的 dll 和你的 exec 没有链接到完全相同的 Qt 核心 dll,你就会遇到问题

关于c++ - QThreadPool maxThreadCount 在应用程序和 DLL 中不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47316556/

相关文章:

c++ - 单个函数指针能否指向多个类的成员函数

windows - 为什么我要使用 "Both"COM 线程模型而不是 "Free"?

java - 当某些事务的顺序很重要时,我如何多线程处理队列消费者?

c++ - QTableWidgetDervied::cellChanged

c++ - QPluginLoader 实例总是返回 null

c++ - 软件浮点和 x87 或 sse 禁用

c++ - 哪些是类成员变量的非共享智能指针

c++ - QRegExp 未按预期运行

python - Qt python 如何知道QPushButton发送了哪些信号?

linux - 在 Linux 上正确链接 boost 多线程库