-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
gh-123358: Use _PyStackRef
in LOAD_DEREF
#130064
Conversation
!buildbot AMD64 Windows Server 2022 NoGIL |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit e4c7608 🤖 The command will test the builders whose names match following regular expression: The builders matched are:
|
@@ -19,7 +20,7 @@ PyCell_SwapTakeRef(PyCellObject *cell, PyObject *value) | |||
PyObject *old_value; | |||
Py_BEGIN_CRITICAL_SECTION(cell); | |||
old_value = cell->ob_ref; | |||
cell->ob_ref = value; | |||
FT_ATOMIC_STORE_PTR_RELEASE(cell->ob_ref, value); |
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.
Naiive question: out of curiosity, why does this need release
? I don't see the acquire
anywhere
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.
We generally want to use at least release
when storing pointers that may be loaded concurrently. This ensures that previously written data is visible before the store of value
to cell->ob_ref
.
For example, we probably initialize value
's type earlier in the program execution:
value->ob_type = &PyFloat_Type; // for example
...
FT_ATOMIC_STORE_PTR_RELEASE(cell->ob_ref, value);
It's really important that value's ob_type
field is visible before the write of value to cell->ob_ref
or a reader might see some previous, garbage data for ob_type
.
The load below uses seq-cst
, which is at least as strong as acquire
. The minimum in the C11/C++11 memory model would be consume
for the load (for data dependencies), but no compiler implements that -- they all just upgrade it to "acquire", so it's kind of a mess.
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.
Thanks for the thorough explanation!
For context, I'm still running into the issues we saw at the sprint in September where some of the tests on Windows time out with this change. |
With the locks around cell reads gone, some of the free threading tests were prone to starvation: the readers were able to run in a tight loop and the writer threads weren't scheduled frequently enough to make timely progress.
Ok, I finally figured out the Windows test timeouts. We have tests like
cpython/Lib/test/test_free_threading/test_type.py Lines 44 to 68 in 90b82f2
I've gone through the |
!buildbot Windows |
🤖 New build scheduled with the buildbot fleet by @colesbury for commit c5c689b 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F130064%2Fmerge The command will test the builders whose names match following regular expression: The builders matched are:
|
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 - nice job figuring out what was going on here!
cell
objects (LOAD_DEREF
) do not scale well #123358