summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-05-13 14:33:13 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2022-05-16 18:17:05 +0000
commit8af70190966e38dc3a697859f427276aecfe44d4 (patch)
treebb1523e17bbcf35117faa9c0fa29e2c2ed62ed26 /src/corelib/thread
parent067b53864112c084587fa9a507eb4bde3d50a6e1 (diff)
QReadWriteLock: fix data race in dtor
We need an acquire fence before we delete the d-pointer. Otherwise, the reads that the dtor performs (QReadWriteLockPrivate contains many non-trivial data types such as std::mutex and QVLA), race against writes performed in other threads. The qWarning() indicates that QReadWriteLock can not rely on external synchronization to ensure a happens-before relationship between reads in the dtor and said writes. While an explicit fence just before the delete would suffice, the guard return is an extremely unlikely error case, and if we ignore it, then loadAcquire() is correct, so use that. Pick-to: 6.3 6.2 5.15 Change-Id: I29773b665a7f864cd6b07a294da326e8b10399b5 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/thread')
-rw-r--r--src/corelib/thread/qreadwritelock.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/thread/qreadwritelock.cpp b/src/corelib/thread/qreadwritelock.cpp
index 9efe04d987..d5602974a6 100644
--- a/src/corelib/thread/qreadwritelock.cpp
+++ b/src/corelib/thread/qreadwritelock.cpp
@@ -124,7 +124,7 @@ QReadWriteLock::QReadWriteLock(RecursionMode recursionMode)
*/
QReadWriteLock::~QReadWriteLock()
{
- auto d = d_ptr.loadRelaxed();
+ auto d = d_ptr.loadAcquire();
if (isUncontendedLocked(d)) {
qWarning("QReadWriteLock: destroying locked QReadWriteLock");
return;