-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-120321: Make gi_frame_state transitions atomic in FT build #142599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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
|
🤖 New build scheduled with the buildbot fleet by @colesbury for commit ac3974d 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F142599%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
| FT_ATOMIC_STORE_INT8_RELEASE(gen->gi_frame_state, FRAME_SUSPENDED + oparg); | ||
| #ifdef Py_GIL_DISABLED | ||
| ((_PyThreadStateImpl *)tstate)->gen_last_frame_state = FRAME_SUSPENDED + oparg; | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to factor this out into a helper function? It's duplicated in ceval.c. Also, having helper to update both would reduce the chance that we update one without the other.
| if (gen->gi_frame_state < FRAME_EXECUTING) { | ||
| gen->gi_frame_state = FRAME_EXECUTING; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these loads need to use atomics (in the FT build)?
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: