From 7a7b19a8fd85849bc0331daa9d03e6633f6f0b70 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Tue, 8 Nov 2011 08:52:52 -0800 Subject: [PATCH] vm: more commentary on lock_console() stuff --- vm/debug.cpp | 3 +++ vm/os-unix.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/vm/debug.cpp b/vm/debug.cpp index a10e323184..4d84433e97 100755 --- a/vm/debug.cpp +++ b/vm/debug.cpp @@ -459,6 +459,9 @@ void factor_vm::factorbug() std::cout << "Starting low level debugger..." << std::endl; + // Even though we've stopped the VM, the stdin_loop thread (see os-*.cpp) + // that pumps the console is still running concurrently. We lock a mutex so + // the thread will take a break and give us exclusive access to stdin. lock_console(); if (!fep_help_was_shown) { diff --git a/vm/os-unix.cpp b/vm/os-unix.cpp index 83ff62e182..f953751799 100755 --- a/vm/os-unix.cpp +++ b/vm/os-unix.cpp @@ -466,6 +466,9 @@ void factor_vm::open_console() void factor_vm::lock_console() { + // Lock the stdin_mutex and send the stdin_loop thread a signal to interrupt + // any read() it has in progress. When the stdin loop iterates again, it will + // try to lock the same mutex and wait until unlock_console() is called. pthread_mutex_lock(&stdin_mutex); pthread_kill(stdin_thread, SIGUSR2); }