Skip to content

Commit f3b89a6

Browse files
authored
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.
1 parent f79ffc8 commit f3b89a6

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Include/internal/pycore_ceval.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ extern void _PyEval_ReleaseLock(PyInterpreterState *, PyThreadState *,
145145
static inline int
146146
_PyEval_IsGILEnabled(PyThreadState *tstate)
147147
{
148-
return tstate->interp->ceval.gil->enabled != 0;
148+
struct _gil_runtime_state *gil = tstate->interp->ceval.gil;
149+
return _Py_atomic_load_int_relaxed(&gil->enabled) != 0;
149150
}
150151

151152
// Enable or disable the GIL used by the interpreter that owns tstate, which

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ race_top:list_get_item_ref
6565
race_top:make_pending_calls
6666
race_top:set_add_entry
6767
race_top:should_intern_string
68-
race_top:_PyEval_IsGILEnabled
6968
race_top:llist_insert_tail
7069
race_top:_Py_slot_tp_getattr_hook
7170
race_top:add_threadstate

0 commit comments

Comments
 (0)