From 0a5045a31ff9858846d5b7679f14ed45c47446b3 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 18 Jul 2022 14:46:24 +0200 Subject: [PATCH] QtConcurrent::ReduceKernel: fix race conditions resultsMapSize is modified inside the runReduce() method, and the writes are protected via mutex lock. However, reads of resultsMapSize through shouldThrottle()/shouldStartThread() (that can be called by multiple threads) are done without a lock. Added the missing locks. Task-number: QTBUG-104787 Change-Id: I700e7b66e67025bc7f570bc8ad69409b82675049 Reviewed-by: Jarek Kobus Reviewed-by: Marc Mutz (cherry picked from commit 7afb093dd77f0ed9a1b4145d2d279810aba411c7) Reviewed-by: Sona Kurazyan --- src/concurrent/qtconcurrentreducekernel.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/concurrent/qtconcurrentreducekernel.h b/src/concurrent/qtconcurrentreducekernel.h index a58739fc410..a2c693d9e2e 100644 --- a/src/concurrent/qtconcurrentreducekernel.h +++ b/src/concurrent/qtconcurrentreducekernel.h @@ -187,11 +187,13 @@ public: inline bool shouldThrottle() { + std::lock_guard locker(mutex); return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount)); } inline bool shouldStartThread() { + std::lock_guard locker(mutex); return (resultsMapSize <= (ReduceQueueStartLimit * threadCount)); } };