mirror of
https://github.com/python/cpython.git
synced 2026-04-14 07:41:00 +00:00
gh-120321: Make gi_yieldfrom thread-safe in free-threading build (#144292)
Add a FRAME_SUSPENDED_YIELD_FROM_LOCKED state that acts as a brief lock, preventing other threads from transitioning the frame state while gen_getyieldfrom reads the yield-from object off the stack.
This commit is contained in:
parent
a7048327ed
commit
a01694dacd
9 changed files with 103 additions and 19 deletions
|
|
@ -3391,7 +3391,9 @@ _PyEval_GetAwaitable(PyObject *iterable, int oparg)
|
|||
else if (PyCoro_CheckExact(iter)) {
|
||||
PyCoroObject *coro = (PyCoroObject *)iter;
|
||||
int8_t frame_state = FT_ATOMIC_LOAD_INT8_RELAXED(coro->cr_frame_state);
|
||||
if (frame_state == FRAME_SUSPENDED_YIELD_FROM) {
|
||||
if (frame_state == FRAME_SUSPENDED_YIELD_FROM ||
|
||||
frame_state == FRAME_SUSPENDED_YIELD_FROM_LOCKED)
|
||||
{
|
||||
/* `iter` is a coroutine object that is being awaited. */
|
||||
Py_CLEAR(iter);
|
||||
_PyErr_SetString(PyThreadState_GET(), PyExc_RuntimeError,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue