From: Sam Gross Date: Wed, 7 Jan 2026 22:56:14 +0000 (-0500) Subject: gh-129824: Fix data race on `runtime->gilstate.check_enabled` (gh-143530) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f11f5ebfe6614de23918e2c0b7eedb3a12a14752;p=thirdparty%2FPython%2Fcpython.git gh-129824: Fix data race on `runtime->gilstate.check_enabled` (gh-143530) --- diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 16fb43ea1914..88dbdb6d139c 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2435,7 +2435,7 @@ new_interpreter(PyThreadState **tstate_p, /* Issue #10915, #15751: The GIL API doesn't work with multiple interpreters: disable PyGILState_Check(). */ - runtime->gilstate.check_enabled = 0; + _Py_atomic_store_int_relaxed(&runtime->gilstate.check_enabled, 0); // XXX Might new_interpreter() have been called without the GIL held? PyThreadState *save_tstate = _PyThreadState_GET(); diff --git a/Python/pystate.c b/Python/pystate.c index f605527598a8..23853f697924 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2832,7 +2832,7 @@ int PyGILState_Check(void) { _PyRuntimeState *runtime = &_PyRuntime; - if (!runtime->gilstate.check_enabled) { + if (!_Py_atomic_load_int_relaxed(&runtime->gilstate.check_enabled)) { return 1; }