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

Add QFuture::waitForSuspended()

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • Core: Threads
    • 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.

      Attachments

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

        Activity

          People

            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

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes