Skip to content
Browse files

Fix a race condition when shutting down audio stream

The main EmuThread (in Core) is responsible for both initialising the
audio stream and shutting it down properly.

When the core is shutting down (when state is State::PowerDown), it is
possible that the CPU or CPU-GPU thread and the UI thread will both
try to stop the audio stream at the same time, which is an issue
because some audio backends such as cubeb are not thread-safe.

This commit prevents the race from ever happening in the first place
by removing the call to AudioCommon::SetSoundStreamRunning from
CPU::RunAdjacentSystems, which is actually completely unnecessary when
shutting down because Core::EmuThread is going to stop the stream and
perform more cleanup anyway.

Should fix
  • Loading branch information...
leoetlino committed May 11, 2019
1 parent a0a0a68 commit 7c46497f0472f633cfea153c4c86d8c04cf04d8a
Showing with 3 additions and 1 deletion.
  1. +3 −1 Source/Core/Core/HW/CPU.cpp
@@ -147,7 +147,9 @@ static void RunAdjacentSystems(bool running)
// NOTE: We're assuming these will not try to call Break or EnableStepping.
// Core is responsible for shutting down the sound stream.
if (s_state != State::PowerDown)

void Stop()

0 comments on commit 7c46497

Please sign in to comment.
You can’t perform that action at this time.