Fix potential race condition in QtConcurrent blocking methods

QtConcurrent::blocking*() methods are using the ExceptionStore directly,
which is not thread safe. In case if there's an exception thrown from
multiple threads there may be a race condition. Added a lock to avoid
that.

Change-Id: I5de9928f91f5f43951b9bf9c4594694dc0ca0328
Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Sona Kurazyan 2020-04-02 10:33:49 +02:00
parent 6a6482cb8d
commit 1812830ac3
2 changed files with 7 additions and 3 deletions

View File

@ -322,10 +322,13 @@ void ThreadEngineBase::run() // implements QRunnable.
void ThreadEngineBase::handleException(const QException &exception)
{
if (futureInterface)
if (futureInterface) {
futureInterface->reportException(exception);
else if (!exceptionStore.hasException())
exceptionStore.setException(exception);
} else {
QMutexLocker lock(&mutex);
if (!exceptionStore.hasException())
exceptionStore.setException(exception);
}
}
#endif

View File

@ -121,6 +121,7 @@ protected:
QThreadPool *threadPool;
ThreadEngineBarrier barrier;
QtPrivate::ExceptionStore exceptionStore;
QBasicMutex mutex;
};