I have a while loop in a separate thread listening on stdin
, waiting for text coming from another process. When my program is exiting, I would like to exit from this while loop and join the thread.
std::string line;
while (std::getline(std::cin, line))
{
std::stringstream linestream(line);
}
CodePudding user response:
This is one of the rare cases where detaching the thread could be appropriate. When the program exits the thread will be terminated.
std::thread thr(whatever);
thr.detach();