Simultaneous input and output in a console
问题 A thread where it prints values infinitely to console and a main thread which is taking user input from the console, but the input values are being mixed with the output of that thread. C++ : cin while cout Did give me a hint on how to move further but I was not able to come up with a solution of my own(as I am new to c++). using namespace std; mutex mtx; void foo() { while (1) { usleep(1000000); cout << "Cake\n"; } } int main() { mtx.lock(); thread t1(foo); string x; while (true) { cin >> x;