A std::condition_variable lets a thread sleep until another thread changes some shared state. The pattern has three parts that always go together: a mutex, the state it protects (bool open_, a queue), and the condition variable.
The waiter locks a std::unique_lock and calls cv.wait(lock, predicate). That checks the predicate, and if it is false, unlocks and sleeps in one step; on waking it locks again and checks again. The notifier changes the state while holding the mutex, then calls notify_one() (one waiter can proceed) or notify_all() (every waiter must look).
Two traps make the predicate essential. A spurious wakeup returns from wait with nothing changed, so a waiter must check again: the simulator injects them in some schedules. A lost wakeup happens when the state changes without the mutex just after a waiter checked it: the notify finds nobody waiting yet, and the waiter sleeps forever. wait_for adds a timeout.
Threads here are simulated. Your program runs on one real thread while a scheduler switches between your threads at shared reads and writes, locks, atomic operations, waits, yields and sleeps, and every test runs under 12 different schedules. The order things can happen in, races at those points and deadlocks are faithful. Real parallel speed-up and weak memory-order effects are not.
Change the state under the mutex, then notify; wait with a predicate.