https://github.com/python/cpython/commit/f3b89a63cbb6d46e5ed40d5cd9813cdf9189ce35
commit: f3b89a63cbb6d46e5ed40d5cd9813cdf9189ce35
branch: main
author: Sam Gross <colesb...@gmail.com>
committer: colesbury <colesb...@gmail.com>
date: 2024-06-02T10:19:02-04:00
summary:

gh-117657: Fix TSAN reported race in `_PyEval_IsGILEnabled`. (#119921)

The GIL may be disabled concurrently with this call so we need to use a
relaxed atomic load.

files:
M Include/internal/pycore_ceval.h
M Tools/tsan/suppressions_free_threading.txt

diff --git a/Include/internal/pycore_ceval.h b/Include/internal/pycore_ceval.h
index bd3ba1225f2597..26ede31b1904b4 100644
--- a/Include/internal/pycore_ceval.h
+++ b/Include/internal/pycore_ceval.h
@@ -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
diff --git a/Tools/tsan/suppressions_free_threading.txt 
b/Tools/tsan/suppressions_free_threading.txt
index f855e9ce2698a5..78dac6ee0c9068 100644
--- a/Tools/tsan/suppressions_free_threading.txt
+++ b/Tools/tsan/suppressions_free_threading.txt
@@ -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

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to