My program has a lot of different threads handling different things, and one of them concerns user input.
Other threads do not have a special way of blocking calls, and those that make the block are network-based, will be interrupted or will return gracefully when the socket is disconnected.
However, the user stream has calls std::cinto capture user input. The effect that this has is that all other threads are dead, the user thread still blocks the userβs input and will only die on the next time input.
Is there a way to check if there is any user input to capture before locking?
I understand that it cin.peek()exists, but from my experience it is blocked if there is nothing to read. Assuming I'm using it correctly
My code is basically an infinite loop that stops when another thread switches the condition variable:
void doLoop()
{
while (running)
{
string input = "";
getline(cin, input);
}
}
I am in windows using VS2013 and cannot use external libraries. I use windows.h and std everywhere.
source
share