summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp')
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index 49ce918caf..cd245030db 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -93,6 +93,7 @@ private slots:
void priorityStart();
void waitForDone();
void clear();
+ void clearWithAutoDelete();
#if QT_DEPRECATED_SINCE(5, 9)
void cancel();
#endif
@@ -976,6 +977,31 @@ void tst_QThreadPool::clear()
QCOMPARE(count.loadRelaxed(), threadPool.maxThreadCount());
}
+void tst_QThreadPool::clearWithAutoDelete()
+{
+ class MyRunnable : public QRunnable
+ {
+ public:
+ MyRunnable() {}
+ void run() override { QThread::usleep(30); }
+ };
+
+ QThreadPool threadPool;
+ threadPool.setMaxThreadCount(4);
+ const int loopCount = 20;
+ const int batchSize = 500;
+ // Should not crash see QTBUG-87092
+ for (int i = 0; i < loopCount; i++) {
+ threadPool.clear();
+ for (int j = 0; j < batchSize; j++) {
+ auto *runnable = new MyRunnable();
+ runnable->setAutoDelete(true);
+ threadPool.start(runnable);
+ }
+ }
+ QVERIFY(threadPool.waitForDone());
+}
+
#if QT_DEPRECATED_SINCE(5, 9)
void tst_QThreadPool::cancel()
{