QMutex: limit moreStress test to idealThreadCount threads

Or the previous limit, 10.

The test has a flaky and failing history, esp on macOS. Trying to
provoke race conditions with more threads than we have cores has little
value.

Change-Id: I99dd2b5a6f64faa83963c279c84fc547416f914f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 4802eec2ff314c561ae54647b453e9d0e4665c6e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2022-07-18 13:08:38 +02:00 committed by Qt Cherry-pick Bot
parent dd8192c8f0
commit d67deb7a11

View File

@ -10,6 +10,7 @@
#include <qelapsedtimer.h>
#include <qmutex.h>
#include <qthread.h>
#include <qvarlengtharray.h>
#include <qwaitcondition.h>
#include <private/qvolatile_p.h>
@ -1300,12 +1301,13 @@ QAtomicInt MoreStressTestThread::errorCount = 0;
void tst_QMutex::moreStress()
{
MoreStressTestThread threads[threadCount];
for (int i = 0; i < threadCount; ++i)
threads[i].start();
QVarLengthArray<MoreStressTestThread, threadCount> threads(qMin(QThread::idealThreadCount(),
int(threadCount)));
for (auto &thread : threads)
thread.start();
QVERIFY(threads[0].wait(one_minute + 10000));
for (int i = 1; i < threadCount; ++i)
QVERIFY(threads[i].wait(10000));
for (auto &thread : threads)
QVERIFY(thread.wait(10000));
qDebug("locked %d times", MoreStressTestThread::lockCount.loadRelaxed());
QCOMPARE(MoreStressTestThread::errorCount.loadRelaxed(), 0);
}