summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthreadpool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qthreadpool.cpp')
-rw-r--r--src/corelib/thread/qthreadpool.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index c7531111da7..f4dc940cc4b 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -481,8 +481,13 @@ QThreadPool *QThreadPoolPrivate::qtGuiInstance()
Q_CONSTINIT static QBasicMutex theMutex;
const QMutexLocker locker(&theMutex);
- if (guiInstance.isNull() && !QCoreApplication::closingDown())
+ if (guiInstance.isNull() && !QCoreApplication::closingDown()) {
guiInstance = new QThreadPool();
+ // Limit max thread to avoid too many parallel threads.
+ // We are not optimized for much more than 4 or 8 threads.
+ if (guiInstance && guiInstance->maxThreadCount() > 4)
+ guiInstance->setMaxThreadCount(qBound(4, guiInstance->maxThreadCount() / 2, 8));
+ }
return guiInstance;
}