]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-117657: Fix TSAN reported race in `_PyEval_IsGILEnabled`. (GH-119921) ...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 2 Jun 2024 14:42:46 +0000 (16:42 +0200)
committerGitHub <noreply@github.com>
Sun, 2 Jun 2024 14:42:46 +0000 (14:42 +0000)
The GIL may be disabled concurrently with this call so we need to use a
relaxed atomic load.
(cherry picked from commit f3b89a63cbb6d46e5ed40d5cd9813cdf9189ce35)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Include/internal/pycore_ceval.h
Tools/tsan/suppressions_free_threading.txt

index bd3ba1225f259761320d9fd26075d309f6229696..26ede31b1904b4e1470318916177a078d27818e0 100644 (file)
@@ -145,7 +145,8 @@ extern void _PyEval_ReleaseLock(PyInterpreterState *, PyThreadState *,
 static inline int
 _PyEval_IsGILEnabled(PyThreadState *tstate)
 {
-    return tstate->interp->ceval.gil->enabled != 0;
+    struct _gil_runtime_state *gil = tstate->interp->ceval.gil;
+    return _Py_atomic_load_int_relaxed(&gil->enabled) != 0;
 }
 
 // Enable or disable the GIL used by the interpreter that owns tstate, which
index 42ab27e6d9906e4b4fa9a20941262b8819e918dd..a451c9dd6bed3143d11c56f9abe5b127b3168016 100644 (file)
@@ -66,7 +66,6 @@ race_top:list_get_item_ref
 race_top:make_pending_calls
 race_top:set_add_entry
 race_top:should_intern_string
-race_top:_PyEval_IsGILEnabled
 race_top:llist_insert_tail
 race_top:_Py_slot_tp_getattr_hook
 race_top:add_threadstate