Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gh-135871: _PyMutex_LockTimed() no longer spins or fails for timeout==0 in no-GIL builds; spin loop now reloads lock state.
3 changes: 2 additions & 1 deletion Python/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
return PY_LOCK_ACQUIRED;
}
}
else if (timeout == 0) {
if (timeout == 0) {
return PY_LOCK_FAILURE;
}

Expand Down Expand Up @@ -89,6 +89,7 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
// Spin for a bit.
_Py_yield();
spin_count++;
v = _Py_atomic_load_uint8_relaxed(&m->_bits);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it fixes a logic bug but it also hurts performance

See Tools/lockbench/lockbench.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review! I'm convinced, this line reduces throughput on my machine by something like 40% for 8 threads. I think changing else if to if still makes sense though. I updated the PR.

continue;
}

Expand Down
Loading