multithreading - C++ write to stdin (in Windows) -
i have multi-threaded windows console app control thread runs user input loop this:
char c; { cin >> c; // alter activity based on c } while(c != 'q') // tell other threads close, .join(), , cleanup
however @ time want program able gracefully quit. obvious way put "q\n"
onto stdin stream. there reasonable way that?
or alternative callback force exit main control loop (on primary thread) program falls through subsequent cleanup methods?
(the closest have found far this requires spawning child process , seems kludgy overkill @ best.)
you can use flag loop break condition of threads. problem interthread-communication can solved synchronization objects came c++11 atomics or mutex.
Comments
Post a Comment