From a488f0784b265d350441f5e38dc9021e9c2a50fc Mon Sep 17 00:00:00 2001 From: Benjamin Poulain Date: Thu, 6 Aug 2009 16:37:07 +0200 Subject: Fix a bug in QProcess. QProcess was not reentrant on Unix QProcess is supposed to be reentrant but was not on Unix. The constructor of QProcessManager could be exectued several time when QProcess is created. The construction is now protected by a mutex. Task-number: 254246 Reviewed-by: Olivier Goffart --- src/corelib/io/qprocess_unix.cpp | 12 +++++++++++- tests/auto/qprocess/tst_qprocess.cpp | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 607b734..168eac2 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -162,7 +162,17 @@ private: QMap children; }; -Q_GLOBAL_STATIC(QProcessManager, processManager) + +Q_GLOBAL_STATIC(QMutex, processManagerGlobalMutex) + +static QProcessManager *processManager() { + // The constructor of QProcessManager should be called only once + // so we cannot use Q_GLOBAL_STATIC directly for QProcessManager + QMutex *mutex = processManagerGlobalMutex(); + QMutexLocker locker(mutex); + static QProcessManager processManager; + return &processManager; +} QProcessManager::QProcessManager() { diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp index d235dff..1ffa360 100644 --- a/tests/auto/qprocess/tst_qprocess.cpp +++ b/tests/auto/qprocess/tst_qprocess.cpp @@ -1224,7 +1224,7 @@ private: //----------------------------------------------------------------------------- void tst_QProcess::processInAThread() { - for (int i = 0; i < 3; ++i) { + for (int i = 0; i < 10; ++i) { TestThread thread; thread.start(); QVERIFY(thread.wait(10000)); -- cgit v0.12