8000 gh-116908: Only write to `_pending_calls.calls_to_do` with atomic ope… · python/cpython@9221ef2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9221ef2

Browse files
authored
gh-116908: Only write to _pending_calls.calls_to_do with atomic operations (#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`.
1 parent fc45998 commit 9221ef2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/ceval_gil.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ _push_pending_call(struct _pending_calls *pending,
671671
pending->calls[i].flags = flags;
672672
pending->last = j;
673673
assert(pending->calls_to_do < NPENDINGCALLS);
674-
pending->calls_to_do++;
674+
_Py_atomic_add_int32(&pending->calls_to_do, 1);
675675
return 0;
676676
}
677677

@@ -701,7 +701,7 @@ _pop_pending_call(struct _pending_calls *pending,
701701
pending->calls[i] = (struct _pending_call){0};
702702
pending->first = (i + 1) % NPENDINGCALLS;
703703
assert(pending->calls_to_do > 0);
704-
pending->calls_to_do--;
704+
_Py_atomic_add_int32(&pending->calls_to_do, -1);
705705
}
706706
}
707707

0 commit comments

Comments
 (0)
0