]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129824: Fix data race on `runtime->gilstate.check_enabled` (gh-143530)
authorSam Gross <colesbury@gmail.com>
Wed, 7 Jan 2026 22:56:14 +0000 (17:56 -0500)
committerGitHub <noreply@github.com>
Wed, 7 Jan 2026 22:56:14 +0000 (17:56 -0500)
Python/pylifecycle.c
Python/pystate.c

index 16fb43ea1914397c2b2ba4d6f8a41abf7de9ca14..88dbdb6d139c5f1f3655132705ba67287adaf0ac 100644 (file)
@@ -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();
index f605527598a86d86d924487fa69b7ac276eb0e82..23853f697924509068fd0b0aaf21c69ce9692ea6 100644 (file)
@@ -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;
     }