]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Quiet TSAN warning about a data race between `start_the_world()` and ...
authormpage <mpage@meta.com>
Mon, 15 Apr 2024 16:17:33 +0000 (09:17 -0700)
committerGitHub <noreply@github.com>
Mon, 15 Apr 2024 16:17:33 +0000 (12:17 -0400)
TSAN erroneously reports a data race between the `_Py_atomic_compare_exchange_int`
on `tstate->state` in `tstate_try_attach()` and the non-atomic load of
`tstate->state` in `start_the_world`. The `_Py_atomic_compare_exchange_int` fails,
but TSAN erroneously treats it as a store.

Python/pystate.c

index acec905484c21f6626ac968f28b5946ff354fdc5..50454020b8fcabe6352fb3a7f32fd0651bb411a2 100644 (file)
@@ -2248,7 +2248,8 @@ start_the_world(struct _stoptheworld_state *stw)
     PyThreadState *t;
     _Py_FOR_EACH_THREAD(stw, i, t) {
         if (t != stw->requester) {
-            assert(t->state == _Py_THREAD_SUSPENDED);
+            assert(_Py_atomic_load_int_relaxed(&t->state) ==
+                   _Py_THREAD_SUSPENDED);
             _Py_atomic_store_int(&t->state, _Py_THREAD_DETACHED);
             _PyParkingLot_UnparkAll(&t->state);
         }