From d2d05f2d762a3cdc5a84b8f8d815ca0b2c1bddaf Mon Sep 17 00:00:00 2001 From: Ry Date: Wed, 27 Jul 2022 14:09:54 -0700 Subject: [PATCH] Hack to ensure the CPU thread exits when the window is closed --- src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.rs b/src/main.rs index d61874c..f73955b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -147,6 +147,7 @@ fn main() { }; let (interrupt_sender, interrupt_receiver) = mpsc::channel::(); + let (exit_sender, exit_receiver) = mpsc::channel::(); let builder = thread::Builder::new().name("cpu".to_string()); builder.spawn({ @@ -157,6 +158,14 @@ fn main() { cpu.interrupt(interrupt); } cpu.execute_memory_instruction(); + if let Ok(_) = exit_receiver.try_recv() { + // the rest of the VM has exited, stop the CPU thread + break; + } + } + if let Ok(_) = exit_receiver.try_recv() { + // the rest of the VM has exited, stop the CPU thread + break; } if !cpu.flag.interrupt { // the cpu was halted and interrupts are disabled @@ -246,6 +255,7 @@ fn main() { if input.update(&event) { // close events if input.quit() { + exit_sender.send(true).unwrap(); *control_flow = ControlFlow::Exit; return; }