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>
bb10
Marc Mutz 2022-05-13 14:33:13 +02:00 committed by Sona Kurazyan
parent 067b538641
commit 8af7019096
1 changed files with 1 additions and 1 deletions

View File

@ -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;