diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2013-01-17 17:12:59 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-18 18:38:22 +0100 |
commit | 90c410872e7bedc11b84ea6f6ab97fb0346ad140 (patch) | |
tree | bc42513ebc88d1eeefaf3c0c288aa261360bee62 /tests/auto/qthreadpool | |
parent | 614a9a435ea4b94080ea12c2fcf98d2699731e34 (diff) | |
download | qt4-tools-90c410872e7bedc11b84ea6f6ab97fb0346ad140.tar.gz |
Fix crashes in tst_qthreadpool on Windows.
Qt 4.8 shows frequent crashes in runMultiple apparently caused
by the QMutex construction in the free functions by different
threads. Use a common QMutex class member instead.
Change-Id: I851d4e2d3637a7b4f404ed843f5360c10caa21f5
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from qtbase/ced523af7a3559b0f30dd2a4406e05418ff7ec89)
Diffstat (limited to 'tests/auto/qthreadpool')
-rw-r--r-- | tests/auto/qthreadpool/tst_qthreadpool.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/tests/auto/qthreadpool/tst_qthreadpool.cpp b/tests/auto/qthreadpool/tst_qthreadpool.cpp index 49a496c416..5d134ab0e1 100644 --- a/tests/auto/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/qthreadpool/tst_qthreadpool.cpp @@ -64,6 +64,12 @@ QRunnable *createTask(FunctionPointer pointer) class tst_QThreadPool : public QObject { Q_OBJECT +public: + tst_QThreadPool(); + ~tst_QThreadPool(); + + static QMutex *functionTestMutex; + private slots: void runFunction(); void createThreadRunFunction(); @@ -92,8 +98,24 @@ private slots: void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); void stressTest(); + +private: + QMutex m_functionTestMutex; }; + +QMutex *tst_QThreadPool::functionTestMutex = 0; + +tst_QThreadPool::tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = &m_functionTestMutex; +} + +tst_QThreadPool::~tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = 0; +} + int testFunctionCount; void sleepTestFunction() @@ -114,19 +136,19 @@ void noSleepTestFunction() void sleepTestFunctionMutex() { - static QMutex testMutex; + Q_ASSERT(tst_QThreadPool::functionTestMutex); QTest::qSleep(1000); - testMutex.lock(); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void noSleepTestFunctionMutex() { - static QMutex testMutex; - testMutex.lock(); + Q_ASSERT(tst_QThreadPool::functionTestMutex); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void tst_QThreadPool::runFunction() |