https://github.com/python/cpython/commit/6493a6aaf3cfd7ccf6bb9de76e1a5c5e28feb75b
commit: 6493a6aaf3cfd7ccf6bb9de76e1a5c5e28feb75b
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: colesbury <[email protected]>
date: 2025-10-20T14:25:42Z
summary:

[3.14] gh-140263: Fix data race in test_lock_two_threads (gh-140264) (gh-140369)

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.
(cherry picked from commit f11ec6e643f54f4ee698f7dfc878812a315f2af4)

Co-authored-by: Sam Gross <[email protected]>

files:
M Modules/_testinternalcapi/test_lock.c

diff --git a/Modules/_testinternalcapi/test_lock.c 
b/Modules/_testinternalcapi/test_lock.c
index 8d8cb992b0e07f..ded76ca9fe6819 100644
--- a/Modules/_testinternalcapi/test_lock.c
+++ b/Modules/_testinternalcapi/test_lock.c
@@ -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);

_______________________________________________
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