Repository navigation
gh-162087: Unlock the first mutex when a two-mutex critical section is skipped during stop-the-world - #162088
Open
maikschulze wants to merge 1 commit into
Open
gh-162087: Unlock the first mutex when a two-mutex critical section is skipped during stop-the-world#162088maikschulze wants to merge 1 commit into
maikschulze wants to merge 1 commit into
Conversation
…tion is skipped during stop-the-world _PyCriticalSection2_BeginSlow() returns early while the world is stopped and records no mutexes, so _PyCriticalSection2_End() unlocks nothing. The inline fast path has already locked the first mutex when it calls the slow path with is_m1_locked set, and that mutex stayed locked after the section. Unlock it in the early return, and add a test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_PyCriticalSection2_BeginSlow()returns early while the interpreter's world is stopped (added for gh-144513) and records no mutexes, so_PyCriticalSection2_End()unlocks nothing. When the inline fast path calls it withis_m1_locked, the first mutex is already locked, and it stayed locked after the section had ended. This unlocks it in that early return.The new test in
_testinternalcapibegins a two-object critical section during a stop-the-world while the second object's mutex is held (standing in for a mutex handed off to a suspended thread), and checks that the first mutex is unlocked afterwards. It aborts on main and passes with the change. With the change the full test suite passes on macOS (free-threaded build).The early return is in 3.15 and, since 3.14.4, in 3.14, so this may want backports. I couldn't find code that reaches this path today; details are in the issue.
I used an AI assistant to investigate this and draft the patch; I reviewed and tested the changes myself.