Use a semaphore instead.
Use a condition variable.
Use a condition variable.