Skip to content

gh-135871: Fix needless spinning in _PyMutex_LockTimed (timeout==0)#135872

Merged
colesbury merged 5 commits intopython:mainfrom
jtibbertsma:fix-issue-135871
Jun 25, 2025
Merged

gh-135871: Fix needless spinning in _PyMutex_LockTimed (timeout==0)#135872
colesbury merged 5 commits intopython:mainfrom
jtibbertsma:fix-issue-135871

Conversation

@jtibbertsma
Copy link
Contributor

@jtibbertsma jtibbertsma commented Jun 24, 2025

  • Move the timeout == 0 guard outside the else so a non-blocking call returns immediately after a failed CAS instead of entering the spin loop.
  • Reload v on every spin iteration, allowing timed/blocking callers to notice an unlock promptly.

No-GIL builds now honor the semantics of non-blocking attempts and avoid wasted CPU; GIL builds are unaffected (MAX_SPIN_COUNT == 0).

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants