]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Fix TSAN reported race in `_PyEval_IsGILEnabled`. (#119921)
authorSam Gross <colesbury@gmail.com>
Sun, 2 Jun 2024 14:19:02 +0000 (10:19 -0400)
committerGitHub <noreply@github.com>
Sun, 2 Jun 2024 14:19:02 +0000 (10:19 -0400)
The GIL may be disabled concurrently with this call so we need to use a
relaxed atomic load.

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 f855e9ce2698a51e52d344bd1dd61f2ef0c33484..78dac6ee0c9068fb86a03576700eb80b79e3481f 100644 (file)
@@ -65,7 +65,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