Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
Consider the following scenario:
Thread A starts a new task that's being run in thread B. There is some common data shared between threads. At some point thread A wants to modify this common data, so it may want to suspend the task before modification. However, the task in not suspended immediately, we must wait for it.
The suggestion is to add a QFuture::waitForSuspended(), which would block the thread A (possibly with wait condition), and release it when the thread B called QPromise::suspendIfRequested() for the corresponding future object. The call to waitForSuspended() should be also released when the associated promise has finished.
After waitForSuspended() finished executing, we are sure that thread B is sleeping (or already finished), so we may safely modify the common data and call QFuture::resume() afterwards (in case QFuture::isSuspended() is true).
In this way suspending could be used also for protecting the access to common data.