below is my code which I have written to recreate a problem observed in a much larger project. This code recreates the problem in the larger project as is. What i don't understand is that as control reaches cv.wait() in worker thread, the thread then blocks further execution of all threads. (Either no thread is running or the worker thread is in an infinite loop and not letting any context switch to master thread). This happens in both debug mode is Visual Studio and the application itself(.exe).
> t1.join();
This, in the place that it's in, makes it all serial.
You create one thread and then wait for it to finish.
You never get to create the other thread.
This shall resolve the problem if createThreads() & Main() doesn't have to do any other tasks/code following the jon() statement.
But say if the Main() or createThreads were to execute few other lines after join how do I do that..? I can think of only 1 solutions:
> I can dettach the threads instead of joining them and let the workerThread()and masterThread() threads run freely, and periodically check for a terminate condition.. if terminate condition is set, then call std::thread::terminate()