Repository navigation
mgs: pause without catching the game thread inside printf - #9
Merged
Merged
Conversation
freeze() suspends the live PSX thread wherever it is. While the game boots
it is not idle and prints a lot, so opening the pause menu in the first
second could suspend it inside printf, holding stdout's lock; the cart's
next log line (Cart::screenshot) then waited for it forever and the device
hung on the pause.
The thread is now suspended while this task holds stdout's and stderr's
locks, so it is either outside stdio or waiting for the lock (and takes it
after the resume).
Reproduced by opening the menu on MGS's first frame (8 ms after the game's
main()): hung, and a core dump showed mgs_th suspended in
printf("TASK START...") and main blocked in __flockfile(stdout). With the
fix, a 25 minute run opening the menu on every game's first frame and then
every 4 s did not hang.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ESP-IDF Size Report for 'Tab5 Emu'
FLASH uses app .bin size or json2 flash sum. RAM sums DRAM+IRAM via idf_size. Percentages shown when totals are available. |
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.
Fixes a hang when the pause menu is opened while MGS is booting.
Cause
mgs::freeze()suspends the live PSX thread wherever it is. During boot the game is never idle and prints a lot, so the pause can suspend it insideprintfwhile it holds stdout's lock. The cart's next log line (inCart::screenshot) then waits for that lock forever.A core dump taken by a temporary watchdog showed:
mgs_thsuspended inprintf("TASK START..."), insideuart_writemainblocked in__flockfile(stdout)→Cart::screenshotFix
The thread is suspended while the pausing task holds stdout's and stderr's locks. The game thread is then either outside stdio, or waiting for the lock, in which case it takes the lock after the resume.
Testing (Tab5)
A temporary stress hook (local only) opened the pause menu on every game's first frame, then every 4 s.
main().🤖 Generated with Claude Code