A bounded buffer with a lock and two condition variables, or two semaphores, and why the wait sits in a while loop.
This interactive visualization needs JavaScript.