summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}
/*!