summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré Klitzing <aklitzing@gmail.com>2020-05-19 12:50:35 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-06-23 18:36:25 +0000
commitc2ef25450a5983cff88a643370382110b56667f5 (patch)
tree27b77b5bebe7fae1681d3e15dbcb606840844d8e
parent47fbaf061f32c47ccd5dbbf8b19d695222b21795 (diff)
Fix living QObject after shutdown of QCoreApplication
QThreadPool is a QObject and must be deleted if the QCoreApplication is being destroyed to release the underlying ThreadData. A Q_GLOBAL_STATIC won't release any memory is not able to manually release it. Task-number: QTBUG-84234 Change-Id: Ia82bcff2b564b753ed687f025ff86fa1bed1e64c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 1304040e5d5af0575cac43aaf1424f72472c7b23) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp4
-rw-r--r--src/corelib/thread/qthreadpool.cpp11
2 files changed, 11 insertions, 4 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 5fdcc9b914..a97b68f372 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -878,8 +878,10 @@ QCoreApplication::~QCoreApplication()
} QT_CATCH (...) {
// swallow the exception, since destructors shouldn't throw
}
- if (globalThreadPool)
+ if (globalThreadPool) {
globalThreadPool->waitForDone();
+ delete globalThreadPool;
+ }
#endif
#ifndef QT_NO_QOBJECT
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index d2dcc32280..950c08ff80 100644
--- a/src/corelib/thread/qthreadpool.cpp
+++ b/src/corelib/thread/qthreadpool.cpp
@@ -40,13 +40,12 @@
#include "qthreadpool.h"
#include "qthreadpool_p.h"
#include "qdeadlinetimer.h"
+#include "qcoreapplication.h"
#include <algorithm>
QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC(QThreadPool, theInstance)
-
/*
QThread wrapper, provides synchronization against a ThreadPool
*/
@@ -478,7 +477,13 @@ QThreadPool::~QThreadPool()
*/
QThreadPool *QThreadPool::globalInstance()
{
- return theInstance();
+ static QPointer<QThreadPool> theInstance;
+ static QBasicMutex theMutex;
+
+ const QMutexLocker locker(&theMutex);
+ if (theInstance.isNull() && !QCoreApplication::closingDown())
+ theInstance = new QThreadPool();
+ return theInstance;
}
/*!