diff options
author | Tianlu Shao <shaotianlu@uniontech.com> | 2021-12-17 10:27:55 +0800 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2021-12-21 14:44:38 +0100 |
commit | a00578d9aa343d4cce28bcc432b083c457269442 (patch) | |
tree | cee89befb1205612d7cb6a5e4945d94654e6dbda /tests | |
parent | 0663d15da6e8a014bb6a22783036a43172eaedcc (diff) | |
download | qtbase-a00578d9aa343d4cce28bcc432b083c457269442.tar.gz |
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
Change-Id: Idd84d1518fc6a225263e6666a0f1de2ccef79c82
(cherry picked from commit 87b93c29be02f0a7ff9424b5e2b6431e20bd4c40)
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp index a4eb2936b5..02eefc4f14 100644 --- a/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp +++ b/tests/auto/concurrent/qtconcurrentrun/tst_qtconcurrentrun.cpp @@ -30,6 +30,8 @@ #include <QString> #include <QtTest/QtTest> +#include <atomic> + using namespace QtConcurrent; class tst_QtConcurrentRun: public QObject @@ -50,6 +52,7 @@ private slots: #endif void functor(); void lambda(); + void nullThreadPool(); }; void light() @@ -732,5 +735,16 @@ void tst_QtConcurrentRun::lambda() } } +// 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" |