From 97b85f4f4e7fc14ff47cd92e4525f7a56864bff4 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 6 Feb 2015 10:50:29 +0100 Subject: [PATCH] QThread: fix race when setting the eventDispatcher Use QMutexLocker to make this thread-safe. Task-number: QTBUG-29452 (cherry picked and adapted from qtbase/f4609b202208fe592d24c7ae3b4a48ee83045497) Change-Id: I5caf71d9a5dc6e3d655eac84426a0c5592772235 Reviewed-by: Louai Al-Khanji --- src/corelib/thread/qthread_symbian.cpp | 2 ++ src/corelib/thread/qthread_unix.cpp | 3 +++ src/corelib/thread/qthread_win.cpp | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/corelib/thread/qthread_symbian.cpp b/src/corelib/thread/qthread_symbian.cpp index 1d3376ef387..607e3ac10b8 100644 --- a/src/corelib/thread/qthread_symbian.cpp +++ b/src/corelib/thread/qthread_symbian.cpp @@ -336,7 +336,9 @@ typedef void*(*QtThreadCallback)(void*); void QThreadPrivate::createEventDispatcher(QThreadData *data) { + QMutexLocker l(&data->postEventList.mutex); data->eventDispatcher = new QEventDispatcherSymbian; + l.unlock(); data->eventDispatcher->startingUp(); } diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 4d85968ceb0..7d8df263565 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -273,6 +273,8 @@ typedef void*(*QtThreadCallback)(void*); void QThreadPrivate::createEventDispatcher(QThreadData *data) { + QMutexLocker l(&data->postEventList.mutex); + #if defined(Q_OS_BLACKBERRY) data->eventDispatcher = new QEventDispatcherBlackberry; #else @@ -286,6 +288,7 @@ void QThreadPrivate::createEventDispatcher(QThreadData *data) data->eventDispatcher = new QEventDispatcherUNIX; #endif + l.unlock(); data->eventDispatcher->startingUp(); } diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index 4ebae9ec24f..01ddf02c26e 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -318,7 +318,9 @@ void qt_set_thread_name(HANDLE threadId, LPCSTR threadName) void QThreadPrivate::createEventDispatcher(QThreadData *data) { + QMutexLocker l(&data->postEventList.mutex); data->eventDispatcher = new QEventDispatcherWin32; + l.unlock(); data->eventDispatcher->startingUp(); }