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:
parent
6a6482cb8d
commit
1812830ac3
@ -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
|
||||
|
||||
|
@ -121,6 +121,7 @@ protected:
|
||||
QThreadPool *threadPool;
|
||||
ThreadEngineBarrier barrier;
|
||||
QtPrivate::ExceptionStore exceptionStore;
|
||||
QBasicMutex mutex;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user