The console is shared by the whole process and this creates a lot of
problems when multiple threads try to read it. In my experience the
cleanest solution is to have an extra dedicated thread for console input
(and also output, if you want it to be displayed nicely). This thread
should sit in an infinite loop and wait for messages/commands from other
threads. When any other thread wants to get some input from the user
then it sends a message/command to the console thread, which outputs the
question/prompt, then reads in the user input and sends it back to the
original thread. Then it goes back to waiting in the infinite loop.
If the user wants to give some command while no thread is asking
anything, he should press Ctrl-C. This should be handled in yet another
thread (see SetConsoleCtrlHandler() and/or sigwait()) which communicates
with the console thread via the exact same mechanism.
To make this post on-topic: in C++ one can conveniently use std::deque
(of course, properly mutex-protected) for such inter-thread message queues.
hth
Paavo