I have a multi-threaded Windows console app whose control thread runs a user input loop like this:
char c;
do {
cin >> c;
// Alter activity based on c
} while(c != 'q')
// Tell other threads to close, .join(), and do cleanup
However at a certain time I want the program itself to be able to gracefully quit. The most obvious way to do so would be to put a "q\n"
onto the stdin stream. Is there a reasonable way to do that?
Or a good alternative for a callback to force exit the main control loop (on the primary thread) so that the program falls through to the subsequent cleanup methods?
(The closest I have found so far is this which requires spawning a child process and seems like kludgy overkill at best.)