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.
This commit is contained in:
Joseph Tibbertsma 2025-06-25 09:41:36 -07:00 committed by GitHub
parent a88b49c3f2
commit cbfaf41caf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View file

@ -0,0 +1,2 @@
Non-blocking mutex lock attempts now return immediately when the lock is busy
instead of briefly spinning in the :term:`free threading` build.

View file

@ -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;
}