c++ - Asynchronous console input froze previous input C -
i want write simple program 3 threads (main, reader, writer). reader thread that:
char message[128]; while (1) { std::cin >> message; }
main thread catch ctrl+z
action , user press controls, want show simple choice do want finish? (y/n) __
__
std::cin
action. have that:
void signal_handler(int signal) { char finish; std::cout << "do want finish? (y/n)"; std::cin >> finish; } int main(void) { signal(20, signal_handler); ...
but when sent simple y
@ first going reader thread, when sent y
going main thread. how can redirect stdin main thread?
standard io (which std::cin
wraps) not thread aware.
it responsibility of multi-threaded application handle it's resources in sensible way.
one way have single thread responsible reading stdin , pushing memory queue controlled multi-threaded aware abstraction code. have resource "locked" required thread required program logic.
Comments
Post a Comment