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 <jaroslaw.kobus@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 7afb093dd77f0ed9a1b4145d2d279810aba411c7)
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Sona Kurazyan 2022-07-18 14:46:24 +02:00
parent e456889840
commit 0a5045a31f

View File

@ -187,11 +187,13 @@ public:
inline bool shouldThrottle()
{
std::lock_guard<QMutex> locker(mutex);
return (resultsMapSize > (ReduceQueueThrottleLimit * threadCount));
}
inline bool shouldStartThread()
{
std::lock_guard<QMutex> locker(mutex);
return (resultsMapSize <= (ReduceQueueStartLimit * threadCount));
}
};