https://github.com/python/cpython/commit/c64df2a3ec39a916a011baaa9b8a305d15bf091c
commit: c64df2a3ec39a916a011baaa9b8a305d15bf091c
branch: 3.13
author: Sam Gross <[email protected]>
committer: colesbury <[email protected]>
date: 2025-06-25T17:09:17Z
summary:

[3.13] gh-135871: Fix needless spinning in `_PyMutex_LockTimed` with zero 
timeout (gh-135872) (gh-135947)

The free threading build could spin unnecessarily on `_Py_yield()` if the 
initial
compare and swap failed.
(cherry picked from commit cbfaf41caf135b8598a560854cd59e992a2ccfed)

Co-authored-by: Joseph Tibbertsma <[email protected]>

files:
A Misc/NEWS.d/next/Core and 
Builtins/2025-06-23-18-08-32.gh-issue-135871.50C528.rst
M Python/lock.c

diff --git a/Misc/NEWS.d/next/Core and 
Builtins/2025-06-23-18-08-32.gh-issue-135871.50C528.rst b/Misc/NEWS.d/next/Core 
and Builtins/2025-06-23-18-08-32.gh-issue-135871.50C528.rst
new file mode 100644
index 00000000000000..ce29ddecefe17f
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and 
Builtins/2025-06-23-18-08-32.gh-issue-135871.50C528.rst 
@@ -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.
diff --git a/Python/lock.c b/Python/lock.c
index 49f46ea36f72ac..24c404a1246130 100644
--- a/Python/lock.c
+++ b/Python/lock.c
@@ -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;
     }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to