Download source code from: https://github.com/prateekparallel/InterThreadCommunication
The first two examples are in C and the last one is in C++. In my first approach, I am using 3 mutexs and 3 condition variables. With the below examples, you can schedule or control any number of threads in C and C++. First, look at the first thread below. Here it locked mutex lock1 (so that other threads could not access the code) starts executing (code not added, just comments) and finally after completing its task waiting on cond1, likewise, the second thread locked mutex lock2, started executing its business logic, and, finally, waited on conditions from cond2 and the third thread locked mutex lock3, started executing its business logic and finally waited for the condition of cond3. I am not adding any business logic here because this is just an example. In the commented section you can add your business logic which will execute in parallel mode. Suppose thread3 depends on the final output of thread1, which is going to be inserted in a table, and thread3 will read that information before creating its final result, and thread2 depends on the final outcome of thread3 to generate its final outcome. Hence thread1, after inserting the data into a table, signals thread3 through the condition variable to go ahead with its final process. That means that thread1 controls thread3. As thread2 depends on the final outcome from thread3, thread3 controls the execution of Thread2. Here, we can allow thread1 to execute independently as its operation does not depend on any other thread, but, for example, for thread control, we are controlling all the threads here and hence thread1 is being controlled from thread2.