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 <marc.mutz@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Allan Sandfeld Jensen
2022-01-12 17:43:40 +01:00
parent 009c91aeec
commit 1421694d17

View File

@@ -408,7 +408,10 @@ QFuture<ResultType> runAsync_internal(QThreadPool *pool,
QFuture<ResultType> future = job->future(); QFuture<ResultType> future = job->future();
if (pool) { if (pool) {
job->setThreadPool(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 { } else {
auto thread = new Internal::RunnableThread(job); auto thread = new Internal::RunnableThread(job);
if (stackSize) if (stackSize)