How to force threads to work in strict order?
问题 I'm writing a multi-thread console application using WinAPI's critical sections as the synchronizing mechanism. I need to create 5 threads, every thread has its own string to be displayed by the thread. Threads should output their strings sequentially, one by one. So, I have thread function: void thread_routine(void* data) { std::string* st = (std::string*)data; while(1) { /* enter critical section */ std::cout << st; // not exactly that way, but I hope that you understood what I've meant.