Details
-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
6.5.0
-
None
-
86c044176 (dev), 07d6d31a4 (dev)
Description
QFuture::then() with a context object has this warning in the docs:
Note: When calling this method, it should be guaranteed that the context stays alive throughout the execution of the chain.
In QTBUG-86794, the reasoning is given:
The problem is that when the thread invoking the continuation is different from the thread where the context object lives, theoretically it can happen that the context gets destroyed at the moment of trying to invoke the continuation in the given context (for example, if during the QMetaObject::invokeMethod(context, ...) call context gets destroyed, we will have problems)
This makes sense. However, QFutureWatcher seems to be able to work around this. In particular, the following construct works fine:
void SomeType::someFunc() { QFuture<void> future = // ... // future.then(this, ...) is bad, because "this" might be destroyed before the future finishes auto *watcher = new QFutureWatcher<void>(this); QtFuture::connect(watcher, &QFutureWatcherBase::finished).then(...); // works, even if "this" and the QFutureWatcher are destroyed early. }
So could the context object functionality simply be implemented the with/similar to QFutureWatcher? Or does QFutureWatcher actually suffer from the same race condition as the continuation (without the assertions, so failing "silently")?
Attachments
Issue Links
- relates to
-
QTBUG-119810 QFuture continuation with deleted context
-
- Closed
-
- resulted in
-
QTBUG-119579 [Reg 6.5 -> 6.6] Calling QPromise::finish() from the same thread deadlocks i
-
- Closed
-