QtConcurrent::run crashes on program exit
When an application is about to be closed and all the destructors are called, if there isQtConcurrent::run on the way, it crashes as the internal threadpool pointer is nullptr. Fixes: QTBUG-98901 Pick-to: 6.2 6.3 Change-Id: Idd84d1518fc6a225263e6666a0f1de2ccef79c82 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
43e9f86cc1
commit
87b93c29be
@ -93,7 +93,13 @@ public:
|
||||
promise.setRunnable(this);
|
||||
promise.reportStarted();
|
||||
QFuture<T> theFuture = promise.future();
|
||||
parameters.threadPool->start(this, parameters.priority);
|
||||
|
||||
if (parameters.threadPool) {
|
||||
parameters.threadPool->start(this, parameters.priority);
|
||||
} else {
|
||||
promise.reportCanceled();
|
||||
promise.reportFinished();
|
||||
}
|
||||
return theFuture;
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,7 @@ private slots:
|
||||
void crefFunction();
|
||||
void customPromise();
|
||||
void nonDefaultConstructibleValue();
|
||||
void nullThreadPool();
|
||||
};
|
||||
|
||||
void light()
|
||||
@ -1577,5 +1578,16 @@ void tst_QtConcurrentRun::nonDefaultConstructibleValue()
|
||||
QCOMPARE(future.result().value, 42);
|
||||
}
|
||||
|
||||
// QTBUG-98901
|
||||
void tst_QtConcurrentRun::nullThreadPool()
|
||||
{
|
||||
QThreadPool *pool = nullptr;
|
||||
std::atomic<bool> isInvoked = false;
|
||||
auto future = run(pool, [&] { isInvoked = true; });
|
||||
future.waitForFinished();
|
||||
QVERIFY(future.isCanceled());
|
||||
QVERIFY(!isInvoked);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QtConcurrentRun)
|
||||
#include "tst_qtconcurrentrun.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user