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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -