From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 25 Jun 2025 17:07:07 +0000 (+0200) Subject: [3.14] gh-135871: Fix needless spinning in `_PyMutex_LockTimed` with zero timeout... X-Git-Tag: v3.14.0b4~100 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80fc62f8af957fe77c8bcf7936a9b2df920671e3;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-135871: Fix needless spinning in `_PyMutex_LockTimed` with zero timeout (gh-135872) (gh-135946) 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 --- 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 000000000000..ce29ddecefe1 --- /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 28a12ad18352..3c0804c468e0 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; }