4 ms·
Control-C handling is pretty horrendous in C/C++ multithreaded programs, too. I remember writing code to re-dispatch the signal to the actual main thread, as a
by pjc50 9y ago
Control-C handling is pretty horrendous in C/C++ multithreaded programs, too. I remember writing code to re-dispatch the signal to the actual main thread, as a different signal, so that we could actually run an interactive menu in the handler.
(It turns out that while you "shouldn't" do POSIX IO from a signal handler, on Linux this works fine 99% of the time so you can write() a menu and read() the input character before deciding whether to stop your program cleanly or uncleanly.)