From d67deb7a1100a67b5ab00c1438c326ab67e59dff Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 18 Jul 2022 13:08:38 +0200 Subject: [PATCH] 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 (cherry picked from commit 4802eec2ff314c561ae54647b453e9d0e4665c6e) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 3449b9109de..e78ebbed2e4 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -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 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); }