]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: more commentary on lock_console() stuff
authorJoe Groff <arcata@gmail.com>
Tue, 8 Nov 2011 16:52:52 +0000 (08:52 -0800)
committerJoe Groff <arcata@gmail.com>
Tue, 8 Nov 2011 16:52:52 +0000 (08:52 -0800)
vm/debug.cpp
vm/os-unix.cpp

index a10e323184550db7a8f813bfb670720a70c6677d..4d84433e97b936cc1122be642e14a16af0c601df 100755 (executable)
@@ -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) {
index 83ff62e18239a73618a079aa926dfe679a5fd93a..f95375179952fef943bb44fc550d2a99075ebfab 100755 (executable)
@@ -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);
 }