https://github.com/python/cpython/commit/0d29302155f49d4d5c7fa34a658ad5a97dd013a2
commit: 0d29302155f49d4d5c7fa34a658ad5a97dd013a2
branch: main
author: mpage <[email protected]>
committer: DinoV <[email protected]>
date: 2024-04-17T17:19:28Z
summary:

gh-117657: Quiet erroneous TSAN reports of data races in `_PySeqLock` (#117955)

Quiet erroneous TSAN reports of data races in `_PySeqLock`

TSAN reports a couple of data races between the compare/exchange in
`_PySeqLock_LockWrite` and the non-atomic loads in 
`_PySeqLock_{Abandon,Unlock}Write`.
This is another instance of TSAN incorrectly modeling failed compare/exchange
as a write instead of a load.

files:
M Python/lock.c
M Tools/tsan/suppressions_free_threading.txt

diff --git a/Python/lock.c b/Python/lock.c
index 7d1ead585dee6c..91c66df8fd9093 100644
--- a/Python/lock.c
+++ b/Python/lock.c
@@ -472,7 +472,7 @@ _PyRWMutex_Unlock(_PyRWMutex *rwmutex)
 
 void _PySeqLock_LockWrite(_PySeqLock *seqlock)
 {
-    // lock the entry by setting by moving to an odd sequence number
+    // lock by moving to an odd sequence number
     uint32_t prev = _Py_atomic_load_uint32_relaxed(&seqlock->sequence);
     while (1) {
         if (SEQLOCK_IS_UPDATING(prev)) {
@@ -492,14 +492,14 @@ void _PySeqLock_LockWrite(_PySeqLock *seqlock)
 
 void _PySeqLock_AbandonWrite(_PySeqLock *seqlock)
 {
-    uint32_t new_seq = seqlock->sequence - 1;
+    uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) - 1;
     assert(!SEQLOCK_IS_UPDATING(new_seq));
     _Py_atomic_store_uint32(&seqlock->sequence, new_seq);
 }
 
 void _PySeqLock_UnlockWrite(_PySeqLock *seqlock)
 {
-    uint32_t new_seq = seqlock->sequence + 1;
+    uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) + 1;
     assert(!SEQLOCK_IS_UPDATING(new_seq));
     _Py_atomic_store_uint32(&seqlock->sequence, new_seq);
 }
diff --git a/Tools/tsan/suppressions_free_threading.txt 
b/Tools/tsan/suppressions_free_threading.txt
index 6e2bdc1ea85cd6..80191d6c2484e6 100644
--- a/Tools/tsan/suppressions_free_threading.txt
+++ b/Tools/tsan/suppressions_free_threading.txt
@@ -26,7 +26,6 @@ race:_PyObject_GC_IS_SHARED
 race:_PyObject_GC_SET_SHARED
 race:_PyObject_GC_TRACK
 race:_PyType_HasFeature
-race:_PyType_Lookup
 race:assign_version_tag
 race:compare_unicode_unicode
 race:delitem_common
@@ -47,4 +46,3 @@ race:set_inheritable
 race:start_the_world
 race:tstate_set_detached
 race:unicode_hash
-race:update_cache_gil_disabled

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to