]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-116908: Only write to `_pending_calls.calls_to_do` with atomic operations (#117044)
authorBrett Simmers <swtaarrs@users.noreply.github.com>
Wed, 20 Mar 2024 15:18:26 +0000 (08:18 -0700)
committerGitHub <noreply@github.com>
Wed, 20 Mar 2024 15:18:26 +0000 (11:18 -0400)
These writes to `pending->calls_to_do` need to be atomic, because other threads
can read (atomically) from `calls_to_do` without holding `pending->mutex`.

Python/ceval_gil.c

index d2cd35dfa86833ee7b47563aedbdc966399ae426..78c13d619e6ee0531645711da2604d0d4dcfd582 100644 (file)
@@ -671,7 +671,7 @@ _push_pending_call(struct _pending_calls *pending,
     pending->calls[i].flags = flags;
     pending->last = j;
     assert(pending->calls_to_do < NPENDINGCALLS);
-    pending->calls_to_do++;
+    _Py_atomic_add_int32(&pending->calls_to_do, 1);
     return 0;
 }
 
@@ -701,7 +701,7 @@ _pop_pending_call(struct _pending_calls *pending,
         pending->calls[i] = (struct _pending_call){0};
         pending->first = (i + 1) % NPENDINGCALLS;
         assert(pending->calls_to_do > 0);
-        pending->calls_to_do--;
+        _Py_atomic_add_int32(&pending->calls_to_do, -1);
     }
 }