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

Application hangs when emit signal on Linux in g_main_context_wakeup

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.8.0
    • Core: Threads
    • None
    • Ubuntu Linux 11.04

    Description

      The event dispatcher of a thread is deleted in:

      qthread_unix.cpp QThreadPrivate::finish()
          QMutexLocker locker(&d->mutex);
          ...
      
          locker.relock();
          d->terminated = false;
      
          QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher;
          if (eventDispatcher) {
              d->data->eventDispatcher = 0;
              locker.unlock();
              eventDispatcher->closingDown();
              delete eventDispatcher;
              locker.relock();
          }
      

      (similar code in qthread_win.cpp)

      But not all of its uses are thread-safe. For example

      qcoreapplication.cpp QCoreApplication::postEvent
          ...
          if (data->eventDispatcher)
              data->eventDispatcher->wakeUp();
      

      QCoreApplication::postEvent locks the post event mutex list, but never does it lock the thread mutex which protects the setting of the eventDispatcher variable.

      Same thing in:

      qeventloop.cpp
      void QEventLoop::wakeUp()
      {
          Q_D(QEventLoop);
          if (!d->threadData->eventDispatcher)
              return;
          d->threadData->eventDispatcher->wakeUp();
      }
      

      And in:

      qobject.cpp QObjectPrivate::setThreadData_helper
          if (eventsMoved > 0 && targetData->eventDispatcher) {
              targetData->canWait = false;
              targetData->eventDispatcher->wakeUp();
          }
      

      This latter function is called with the post event mutexes locked, but not the QThreadPrivate::mutex mutex.

      One could argue that the QEventLoop one isn't supposed to be called from outside the thread (it's not marked as \threadsafe), but QCoreApplication::postEvent is and QObject::moveToThread does not mention a problem with moving to a thread that is exiting.

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              kirill2010 Kirill
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes