mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-123358: Use _PyStackRef
in LOAD_DEREF
(gh-130064)
Concurrent accesses from multiple threads to the same `cell` object did not scale well in the free-threaded build. Use `_PyStackRef` and optimistically avoid locking to improve scaling. 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. Adjust the tests to avoid this. Co-authored-by: Donghee Na <donghee.na@python.org>
This commit is contained in:
parent
1b8bb1ed0c
commit
3d4ac1a2c2
12 changed files with 90 additions and 44 deletions
10
Python/generated_cases.c.h
generated
10
Python/generated_cases.c.h
generated
|
@ -8822,14 +8822,18 @@
|
|||
INSTRUCTION_STATS(LOAD_DEREF);
|
||||
_PyStackRef value;
|
||||
PyCellObject *cell = (PyCellObject *)PyStackRef_AsPyObjectBorrow(GETLOCAL(oparg));
|
||||
PyObject *value_o = PyCell_GetRef(cell);
|
||||
if (value_o == NULL) {
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
value = _PyCell_GetStackRef(cell);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
if (PyStackRef_IsNull(value)) {
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
_PyFrame_SetStackPointer(frame, stack_pointer);
|
||||
_PyEval_FormatExcUnbound(tstate, _PyFrame_GetCode(frame), oparg);
|
||||
stack_pointer = _PyFrame_GetStackPointer(frame);
|
||||
JUMP_TO_LABEL(error);
|
||||
}
|
||||
value = PyStackRef_FromPyObjectSteal(value_o);
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue