summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorAndré Klitzing <aklitzing@gmail.com>2020-05-19 12:50:35 +0200
committerAndré Klitzing <aklitzing@gmail.com>2020-06-23 08:31:00 +0200
commit1304040e5d5af0575cac43aaf1424f72472c7b23 (patch)
tree25a3f6e5bb6f1364c73dd8e293e8b89ea9130e82 /src/corelib/thread
parent727fab7d291d8d6e1b61a7faec4b4318f714d1e0 (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. Pick-to: 5.15 Task-number: QTBUG-84234 Change-Id: Ia82bcff2b564b753ed687f025ff86fa1bed1e64c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthreadpool.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp
index 9657112abc..1478cfcb19 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;
}
/*!