summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/thread
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-18 13:08:38 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-07-20 06:57:43 +0200
commit4802eec2ff314c561ae54647b453e9d0e4665c6e (patch)
treed1f0442b44871116c5fce6f5cb11bd29204fcc2b /tests/auto/corelib/thread
parent86d973ed077b3e8e89571b2c3327f15d3ad89eed (diff)
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. Pick-to: 6.4 Change-Id: I99dd2b5a6f64faa83963c279c84fc547416f914f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/thread')
-rw-r--r--tests/auto/corelib/thread/qmutex/tst_qmutex.cpp12
1 files 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 3449b9109d..e78ebbed2e 100644
--- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
+++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp
@@ -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);
}