Skip to content

Commit 0d29302

Browse files
authored
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.
1 parent b6c62c7 commit 0d29302

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Python/lock.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ _PyRWMutex_Unlock(_PyRWMutex *rwmutex)
472472

473473
void _PySeqLock_LockWrite(_PySeqLock *seqlock)
474474
{
475-
// lock the entry by setting by moving to an odd sequence number
475+
// lock by moving to an odd sequence number
476476
uint32_t prev = _Py_atomic_load_uint32_relaxed(&seqlock->sequence);
477477
while (1) {
478478
if (SEQLOCK_IS_UPDATING(prev)) {
@@ -492,14 +492,14 @@ void _PySeqLock_LockWrite(_PySeqLock *seqlock)
492492

493493
void _PySeqLock_AbandonWrite(_PySeqLock *seqlock)
494494
{
495-
uint32_t new_seq = seqlock->sequence - 1;
495+
uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) - 1;
496496
assert(!SEQLOCK_IS_UPDATING(new_seq));
497497
_Py_atomic_store_uint32(&seqlock->sequence, new_seq);
498498
}
499499

500500
void _PySeqLock_UnlockWrite(_PySeqLock *seqlock)
501501
{
502-
uint32_t new_seq = seqlock->sequence + 1;
502+
uint32_t new_seq = _Py_atomic_load_uint32_relaxed(&seqlock->sequence) + 1;
503503
assert(!SEQLOCK_IS_UPDATING(new_seq));
504504
_Py_atomic_store_uint32(&seqlock->sequence, new_seq);
505505
}

Tools/tsan/suppressions_free_threading.txt

-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ race:_PyObject_GC_IS_SHARED
2626
race:_PyObject_GC_SET_SHARED
2727
race:_PyObject_GC_TRACK
2828
race:_PyType_HasFeature
29-
race:_PyType_Lookup
3029
race:assign_version_tag
3130
race:compare_unicode_unicode
3231
race:delitem_common
@@ -47,4 +46,3 @@ race:set_inheritable
4746
race:start_the_world
4847
race:tstate_set_detached
4948
race:unicode_hash
50-
race:update_cache_gil_disabled

0 commit comments

Comments
 (0)