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

Race condition in QThread

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • 4.8.0
    • 4.7.1
    • Core: Threads
    • None
    • a77ab4c4dd3c0d9c5cf71afc4d3efcc76a068430

      It's about setting "quitNow" flag in the QThread::exec() and checking this flag in the QEvenLoop::exec().

      The QThread::quit() can tell the loop to quit in two ways: setting "quitNow" flag it there's no loop yet and posting a message into the loop if it already exists.

      There's unprotected area in the QEventLoop::exec() (qeventloop.cpp, lines 180-186) where the flag is ALREADY checked but the loop message queue DOESN'T EXIST yet (d->threadData->eventLoops.push(this) not called yet).

      If the execution point being in this area and the thread's quit() method is called from another thread, this request is lost, because the flag won't be checked again and queue not accepting messages yet.

      Test Case is attached. The problem arises randomly though.

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

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes