Blocking Issues
To make my point clear, you have to use a condition variable in combination with a predicate. If you don’t, your program may become a victim of a spurious wakeup or lost wakeup.
If you use a condition variable without a predicate, the notifying thread may send its notification before the waiting thread is waiting. Therefore, the waiting thread waits forever. This phenomenon is called a lost wakeup.
Here is the program.