]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-135871: Fix needless spinning in `_PyMutex_LockTimed` with zero timeout...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 25 Jun 2025 17:07:07 +0000 (19:07 +0200)
committerGitHub <noreply@github.com>
Wed, 25 Jun 2025 17:07:07 +0000 (17:07 +0000)
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 <josephtibbertsma@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2025-06-23-18-08-32.gh-issue-135871.50C528.rst [new file with mode: 0644]
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 (file)
index 0000000..ce29dde
--- /dev/null
@@ -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.
index 28a12ad18352d1e1fac0d088876075993bda0701..3c0804c468e08dd83da2675687e674164a1bf4f5 100644 (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;
     }