summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorjian liang <jianliang79@gmail.com>2012-02-19 14:09:44 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-02-28 14:35:06 (GMT)
commit50ad6db629ecd268192023ad97577c51c9b19c32 (patch)
tree19aaf0633a3a02c6f52dc599c0ee2534dba3f897 /src/corelib/thread
parentaaa46755dcc15b8baaa0d1b928828eb60e0babbc (diff)
downloadQt-50ad6db629ecd268192023ad97577c51c9b19c32.zip
Qt-50ad6db629ecd268192023ad97577c51c9b19c32.tar.gz
Qt-50ad6db629ecd268192023ad97577c51c9b19c32.tar.bz2
Fix potential race condition in data structure of adopted thread watcher
Fix potential race condition in data structure of adopted thread watcher in Windows. Since QVector is not thread safe, it is not safe to read and append data to qt_adopted_thread_handles or qt_adopted_qthread simultaneously in qthread_win.cpp. This patch fix this race condition. Change-Id: I2d0c7a4cdde5390d38d15c98343f0fc6ddd24aba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> (cherry picked from commit 4b30882a3f74914156f165a0a062b54ad3686c45)
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qthread_win.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp
index db9c61c..4dc7b63 100644
--- a/src/corelib/thread/qthread_win.cpp
+++ b/src/corelib/thread/qthread_win.cpp
@@ -234,7 +234,9 @@ void qt_adopted_thread_watcher_function(void *)
// printf("(qt) - qt_adopted_thread_watcher_function... called\n");
const int qthreadIndex = handleIndex - 1;
+ qt_adopted_thread_watcher_mutex.lock();
QThreadData *data = QThreadData::get2(qt_adopted_qthreads.at(qthreadIndex));
+ qt_adopted_thread_watcher_mutex.unlock();
if (data->isAdopted) {
QThread *thread = data->thread;
Q_ASSERT(thread);
@@ -244,10 +246,10 @@ void qt_adopted_thread_watcher_function(void *)
}
data->deref();
+ QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
#if !defined(Q_OS_WINCE) || (defined(_WIN32_WCE) && (_WIN32_WCE>=0x600))
CloseHandle(qt_adopted_thread_handles.at(handleIndex));
#endif
- QMutexLocker lock(&qt_adopted_thread_watcher_mutex);
qt_adopted_thread_handles.remove(handleIndex);
qt_adopted_qthreads.remove(qthreadIndex);
}