From f11f5ebfe6614de23918e2c0b7eedb3a12a14752 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 7 Jan 2026 17:56:14 -0500 Subject: [PATCH] gh-129824: Fix data race on `runtime->gilstate.check_enabled` (gh-143530) --- Python/pylifecycle.c | 2 +- Python/pystate.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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; } -- 2.47.3