Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c64df2a

Browse files
[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 cbfaf41) Co-authored-by: Joseph Tibbertsma <[email protected]>
1 parent 86c050a commit c64df2a

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)