Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTVU: Fix freeze on shutdown #4483

Merged
merged 1 commit into from
Jul 5, 2021

Conversation

TellowKrinkle
Copy link
Member

Description of Changes

Fixes an issue where the entire emulator could freeze attempting to shut down.

The waitGS function (called by the MTVU thread) waits for the MTGS work queue to empty entirely by spinning on a lock that the MTGS thread normally holds while it's working. This caused two issues:

  • If the MTGS thread pauses with work in the queue, it drops the lock causing the MTVU thread to spin instead of waiting patiently
  • If the MTGS thread exits with work in the queue, the MTVU thread will wait forever for a nonexistent MTGS thread to empty the queue

While we don't really care about MTVU state in the case of an exit, we would like to not abort in the case of a pause since otherwise unpausing will not work.

Based on this, there are two possible solutions:

  1. Make waitGS verify that the the MTGS thread is still running, and allow itself to be paused and cancelled in the case that the MTGS thread is not running
  2. Make the MTGS thread not pause if it has work in its queue

The MTGS thread holds a mutex (mtxBusy) throughout operation (including calls to waitGS), which would need to be dropped if we want to pause the thread (otherwise the emulator will deadlock on exit). While this does remain an option, the consequences of dropping that mutex in the middle of operation would need to be investigated first.

At the moment, option 2 seems like the easier option, and is what is implemented here. I don't expect anything bad to come from it, other than taking an extra frame or two to pause, but you never know.

Rationale behind Changes

Included in the Description of Changes section

Suggested Testing Steps

Play games, pause and unpause the emulator a lot, try to quit the emulator. Observe CPU usage when paused (it should be very low).

Prevents other threads from freezing waiting for the queue to empty when it never will
@refractionpcsx2 refractionpcsx2 merged commit 4116aed into PCSX2:master Jul 5, 2021
inactive123 added a commit to libretro/LRPS2 that referenced this pull request Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants