Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34k
gh-128421: Add locking to most frame object functions#131479
gh-128421: Add locking to most frame object functions#131479colesbury merged 6 commits intopython:mainfrom
Conversation
This makes more operations on frame objects thread-safe in the freethreaded build, which fixes some data races that occurred when passingexceptions between threads.However, accessing local variables from another thread while its runningis still not thread-safe and may crash the interpreter.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
colesbury commentedMar 21, 2025
I added the additional critical sections, although I'm pretty ambivalent about having them in the C APIs. |
kumaraditya303 left a comment
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.
LGTM
4f32516 intopython:mainUh oh!
There was an error while loading.Please reload this page.
The recent PRpythongh-131479 added locking to `take_ownership` in the freethreading build. The cost is not really the locking -- that path isn'ttaken frequently -- but the inlined code causes extra register spillsand slows down RETURN_VALUE, even when it's not taken.Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression.
The recent PRpythongh-131479 added locking to `take_ownership` in the freethreading build. The cost is not really the locking -- that path isn'ttaken frequently -- but the inlined code causes extra register spillsand slows down RETURN_VALUE, even when it's not taken.Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression.Also limit locking in PyFrameObject to Python functions, not the C API.
The recent PRpythongh-131479 added locking to `take_ownership` in the freethreading build. The cost is not really the locking -- that path isn'ttaken frequently -- but the inlined code causes extra register spillsand slows down RETURN_VALUE, even when it's not taken.Mark `take_ownership` as `Py_NO_INLINE` to avoid the regression.Also limit locking in PyFrameObject to Python functions, not the C API.PyFrame_GetCode is called frequently by coverage and tracing tools.
Uh oh!
There was an error while loading.Please reload this page.
This makes more operations on frame objects thread-safe in the free threaded build, which fixes some data races that occurred when passing exceptions between threads.
However, accessing local variables or the line number of a frame from another thread while its still executing is not thread-safe and may crash the interpreter.