Details
-
User Story
-
Resolution: Done
-
P2: Important
-
6.0
-
None
-
13
-
Qt6_Foundation_Sprint 16
Description
Consider the following code:
QPromise<int> promise; QFuture<int> future = promise.future(); QPointer<QThread> thread(QThread::create([] (QPromise<int> promise) { promise.reportStarted(); promise.addResult(42); promise.reportFinished(); // notifies QFuture that the computation is finished }, std::move(promise))); thread->start(); future.waitForFinished();
It can happen, that waitForFinished() may be hit before executing reportStarted() in the working thread. Currently, if reportStarted() was not called before waitForFinished(), the waitForFinished() call won't block. In this case the above code won't work as expected.
That's why we need to wait also for reportStarted() inside waitForFinished(). If we don't want to do behavioral change, we may optionally provide an overload for waitForFinished() or provide a new method.
The idea came from: https://codereview.qt-project.org/c/qt/qtbase/+/302631