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>
This commit is contained in:
Friedemann Kleint 2013-01-17 17:12:59 +01:00 committed by The Qt Project
parent 01d5c6c949
commit ced523af7a

View File

@ -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()