gh-120321: Make gi_frame_state transitions atomic in FT build (gh-142599)

This makes generator frame state transitions atomic in the free
threading build, which avoids segfaults when trying to execute
a generator from multiple threads concurrently.

There are still a few operations that aren't thread-safe and may crash
if performed concurrently on the same generator/coroutine:

 * Accessing gi_yieldfrom/cr_await/ag_await
 * Accessing gi_frame/cr_frame/ag_frame
 * Async generator operations
This commit is contained in:
Sam Gross 2025-12-19 14:10:37 -05:00 committed by GitHub
parent e2a7db7175
commit 08bc03ff2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 1124 additions and 883 deletions

View file

@ -642,6 +642,7 @@ NON_ESCAPING_FUNCTIONS = (
"_PyFrame_StackPush",
"_PyFunction_SetVersion",
"_PyGen_GetGeneratorFromFrame",
"gen_try_set_executing",
"_PyInterpreterState_GET",
"_PyList_AppendTakeRef",
"_PyList_ITEMS",