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

QMutex deadlocks while calling QThread::isRunning() in a slot which connected to QThread::finished() that emitted from QThread::terminate()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • Some future release
    • 4.5.3, 4.6.0
    • Core: Threads
    • None

    Description

      QMutex deadlocks while calling QThread::isRunning() in a slot which connected to QThread::finished() that emitted from QThread::terminate().

      connect(thread, SIGNAL(finished()), this, SLOT(finish()));
      thread->start();
      ...
      thread->terminate();

      so QThread will emit finished() from terminate() function, cause slot:

      THIS::finish() {
      thread->isRunning(); //QMutext DeadLock!
      }

      mutex in QThread is locked when entering terminate(). So when isRunning() is called from connected slot, thread deadlocks.

      void QThread::terminate()
      {
      Q_D(QThread);
      QMutexLocker locker(&d->mutex); //locked here
      ...
      QThreadPrivate::finish(this, false);
      }

      -------------------------

      void QThreadPrivate::finish(void *arg, bool lockAnyway)
      {
      ...
      if (d->terminated)
      emit thr->terminated();
      d->terminated = false;
      emit thr->finished(); //emit signal, process slots.
      ...

      -------------------------

      bool QThread::isRunning() const
      {
      Q_D(const QThread);
      QMutexLocker locker(&d->mutex); //DEAD LOCKED here
      return d->running;
      }

      Attachments

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

        Activity

          People

            goffart Olivier Goffart (closed Nokia identity) (Inactive)
            bi11 Yuxin Wang
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes