8000 Fix needless spinning in `_PyMutex_LockTimed` with zero timeout (gh-1… · python/cpython@cbfaf41 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbfaf41

Browse files
authored
Fix needless spinning in _PyMutex_LockTimed with zero timeout (gh-135872)
The free threading build could spin unnecessarily on `_Py_yield()` if the initial compare and swap failed.
1 parent a88b49c commit cbfaf41

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Non-blocking mutex lock attempts now return immediately when the lock is busy
2+
instead of briefly spinning in the :term:`free threading` build.

Python/lock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
5858
return PY_LOCK_ACQUIRED;
5959
}
6060
}
61-
else if (timeout == 0) {
61+
if (timeout == 0) {
6262
return PY_LOCK_FAILURE;
6363
}
6464

0 commit comments

Comments
 (0)
0