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:
parent
01d5c6c949
commit
ced523af7a
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user