Skip to content

Commit f11ec6e

Browse files
authored
pythongh-140263: Fix data race in test_lock_two_threads (pythongh-140264)
Clang-20 detects a data race between the unlock and the non-atomic read of the lock state. Use a relaxed load for the assertion to avoid the race.
1 parent e4f6445 commit f11ec6e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Modules/_testinternalcapi/test_lock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ test_lock_two_threads(PyObject *self, PyObject *obj)
9191
} while (v != 3 && iters < 200);
9292

9393
// both the "locked" and the "has parked" bits should be set
94-
assert(test_data.m._bits == 3);
94+
v = _Py_atomic_load_uint8_relaxed(&test_data.m._bits);
95+
assert(v == 3);
9596

9697
PyMutex_Unlock(&test_data.m);
9798
PyEvent_Wait(&test_data.done);

0 commit comments

Comments
 (0)