]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-140263: Fix data race in test_lock_two_threads (gh-140264)
authorSam Gross <colesbury@gmail.com>
Mon, 20 Oct 2025 13:58:05 +0000 (09:58 -0400)
committerGitHub <noreply@github.com>
Mon, 20 Oct 2025 13:58:05 +0000 (09:58 -0400)
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.

Modules/_testinternalcapi/test_lock.c

index 8d8cb992b0e07fc66e3282d00e005910827ac630..ded76ca9fe6819436ec608e2211fb4674b0badb8 100644 (file)
@@ -91,7 +91,8 @@ test_lock_two_threads(PyObject *self, PyObject *obj)
     } while (v != 3 && iters < 200);
 
     // both the "locked" and the "has parked" bits should be set
-    assert(test_data.m._bits == 3);
+    v = _Py_atomic_load_uint8_relaxed(&test_data.m._bits);
+    assert(v == 3);
 
     PyMutex_Unlock(&test_data.m);
     PyEvent_Wait(&test_data.done);