From 1421694d17d464be59478d573a7873f86b6fd2a2 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 12 Jan 2022 17:43:40 +0100 Subject: [PATCH] Avoid starting threads from the wrong hosting thread This should be safe for QThreadPool, but we are still fixing an underlying bug, QTBUG-99775, and Qt Creator may just want to avoid the issue altogether. Change-Id: I50041cc6f5974d234b1a07be5cb19108fba897c7 Reviewed-by: Marc Mutz Reviewed-by: Eike Ziller --- src/libs/utils/runextensions.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/runextensions.h b/src/libs/utils/runextensions.h index e7b9dd6c939..9339f1a52ee 100644 --- a/src/libs/utils/runextensions.h +++ b/src/libs/utils/runextensions.h @@ -408,7 +408,10 @@ QFuture runAsync_internal(QThreadPool *pool, QFuture future = job->future(); if (pool) { job->setThreadPool(pool); - pool->start(job); + if (QThread::currentThread() == pool->thread()) + pool->start(job); + else + QMetaObject::invokeMethod(pool, [pool, job]() { pool->start(job); }, Qt::QueuedConnection); } else { auto thread = new Internal::RunnableThread(job); if (stackSize)