Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.6, 6.7.2
-
6efec3850 (dev), 5a9c51323 (6.8), 7b47ce94d (tqtc/lts-6.5)
-
Foundation Sprint 118, Foundation Sprint 119
Description
https://doc.qt.io/qt-6/qpromise.html#setException says, "This method must not be used after QFuture::cancel() or QPromise::finish()". But how can we write code that guarantees that QPromise::setException() won't be called after QFuture::cancel()? The former is meant to be called from the "promise thread" while the latter is meant to be called from the "future thread".
Consider this sequence of events:
- Thread A creates a QPromise + QFuture, then passes the QPromise to Thread B
- Thread B starts doing work
- Thread A requests cancellation
- Thread B has an error and wants to call setException()
// Inside Thread B if (!promise->isCanceled()) { // isCanceled() returns false here // ... // Uh-oh, isCanceled() could return true here! promise->setException(MyException()); }
Suggestion
We need a function that "atomically" checks the cancellation flag and stores the exception if not cancelled. For example, bool setExceptionIfNotCanceled(const QException &) – return true if the exception was set, false otherwise.
Attachments
For Gerrit Dashboard: QTBUG-128405 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
603829,1 | QPromise: fix documentation re:setException() after cancel() or finish() | tqtc/lts-6.2 | qt/tqtc-qtbase | Status: NEW | +2 | 0 |
600867,7 | QPromise: fix documentation re:setException() after cancel() or finish() | dev | qt/qtbase | Status: MERGED | +2 | 0 |
602814,2 | QPromise: fix documentation re:setException() after cancel() or finish() | 6.8 | qt/qtbase | Status: MERGED | +2 | 0 |
603212,3 | QPromise: fix documentation re:setException() after cancel() or finish() | tqtc/lts-6.5 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |