diff options
author | Olivier Goffart <olivier.goffart@nokia.com> | 2010-11-24 14:32:23 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-11-24 15:02:36 (GMT) |
commit | 25c9b6ed488b1446cbdd38186992957264596314 (patch) | |
tree | 75eb8d69df9bd07f93dd1a75dd7d014486b11bd6 /src/corelib/thread/qthread_win.cpp | |
parent | 68e5673bb1ca080bbaf5cf7198fcf2deafa60772 (diff) | |
download | Qt-25c9b6ed488b1446cbdd38186992957264596314.zip Qt-25c9b6ed488b1446cbdd38186992957264596314.tar.gz Qt-25c9b6ed488b1446cbdd38186992957264596314.tar.bz2 |
QThread: fix a race condition when destroying or restarting thread from finished()
Since we do not keep the mutex locked in QThreadPrivate::finish,
We could have races if the thread is destroyed or restarted from
another thread while we are still in that function
This solve tst_QCoreApplication::deliverInDefinedOrder on mac
Regression since a43583e0221311b7fe666726a
Reviewed-by: Brad
Diffstat (limited to 'src/corelib/thread/qthread_win.cpp')
-rw-r--r-- | src/corelib/thread/qthread_win.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 3706da8..74fedd3 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -324,6 +324,7 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway) QThreadPrivate *d = thr->d_func(); QMutexLocker locker(lockAnyway ? &d->mutex : 0); + d->isInFinish = true; d->priority = QThread::InheritPriority; bool terminated = d->terminated; void **tls_data = reinterpret_cast<void **>(&d->data->tls); @@ -348,7 +349,7 @@ void QThreadPrivate::finish(void *arg, bool lockAnyway) d->running = false; d->finished = true; - + d->isInFinish = false; if (!d->waiters) { CloseHandle(d->handle); @@ -405,6 +406,12 @@ void QThread::start(Priority priority) Q_D(QThread); QMutexLocker locker(&d->mutex); + if (d->isInFinish) { + locker.unlock(); + wait(); + locker.relock(); + } + if (d->running) return; |