Where should i put the lock and unlock mutex in order for the threads to print alternatively? Thanks:D
Implement a program that creates two threads. The threads will pr
If you want the predictably ordered output A, B, A, B, A, B, the most appropriate tool to use is a single thread of control.
To do it wastefully with two threads, you can define a shared variable called "turn" which indicates whose turn it is to print something. Each thread waits on a condition variable until the "turn" variable is equal to itself. Then it carries out the sequential task, sets the "turn" variable to another thread and signals the condition.