Skip to content

Commit

Permalink
pythongh-116908: Only write to _pending_calls.calls_to_do with atom…
Browse files Browse the repository at this point in the history
…ic operations (python#117044)

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`.
  • Loading branch information
swtaarrs authored Mar 20, 2024
1 parent fc45998 commit 9221ef2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9221ef2

Please sign in to comment.