From d51bb8b1cc7972a399adfb3eaadf8d602a41f386 Mon Sep 17 00:00:00 2001 From: Eladash Date: Tue, 2 Mar 2021 17:00:16 +0200 Subject: [PATCH] Fix Emulator::Pause race with IDM --- rpcs3/Emu/CPU/CPUThread.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index f0ecf35331..bd69a41b37 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -597,6 +597,23 @@ cpu_thread::~cpu_thread() cpu_thread::cpu_thread(u32 id) : id(id) { + while (Emu.GetStatus() == system_state::paused) + { + // Solve race between Emulator::Pause and this construction of thread which most likely is guarded by IDM mutex + state += cpu_flag::dbg_global_pause; + + if (Emu.GetStatus() != system_state::paused) + { + // Emulator::Resume was called inbetween + state -= cpu_flag::dbg_global_pause; + + // Recheck if state is inconsistent + continue; + } + + break; + } + g_threads_created++; }