runOnAndroidMainThread(): Don't block QThreadPool::globalInstance() with timout awaiters
A waiting task on QThreadPool::globalInstance() will block the worker thread that it was scheduled on, making it unavailable for productive work. That's why one should only put CPU-bound tasks onto QThreadPool::globalInstance(). When blocking nonetheless, use the releaseThread()/reserveThread() trick to avoid deadlocks caused by the pool running out of workers. So, do that here. Task-number: QTBUG-109586 Change-Id: Ia2660c69e1f23b5df0c308576301aac6e05d4725 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit c0496013484c35ab9b1a29ffb0f1eb687ef6db78) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
db7d301f97
commit
f9e9dd19cc
@ -176,6 +176,14 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
|
|||||||
loop.quit();
|
loop.quit();
|
||||||
});
|
});
|
||||||
watcher.setFuture(future);
|
watcher.setFuture(future);
|
||||||
|
|
||||||
|
// we're going to sleep, make sure we don't block
|
||||||
|
// QThreadPool::globalInstance():
|
||||||
|
|
||||||
|
QThreadPool::globalInstance()->releaseThread();
|
||||||
|
const auto sg = qScopeGuard([] {
|
||||||
|
QThreadPool::globalInstance()->reserveThread();
|
||||||
|
});
|
||||||
loop.exec();
|
loop.exec();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user