Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-91884

Add QFuture::waitForSuspended()

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Core: Threads
    • None

      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.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            sonakur Sona Kurazyan
            jkobus Jarek Kobus
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes