Details
-
Bug
-
Resolution: Duplicate
-
P2: Important
-
4.5.3, 4.6.0
-
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;
}