jeudi 22 janvier 2015

C++ CLI multithread: std::cin text gets overriden by other threads output

I implemented a multithreaded C++11 console and I have the following loop fetching commands:



while (_valid) {

/* print newline with '>' */
cout << "\r> ";

if (cin.fail() || cin.eof()) {
cin.clear(); /* reset cin state */
}
/* random parser function, not relevant */
_parse_cmd(_input);

}


This has a huge problem: when I am inputting a new command by keyboard, if there is a thread running on the background and that thread prints anything, it will override my current keyboard input and it will disappear, but my input will remain on the cin buffer.


How can I re-print the current keyboard output?


Aucun commentaire:

Enregistrer un commentaire