Last Updated: May 17, 2026
Sometimes a thread can't make progress until something happens elsewhere: an order is marked ready, inventory is restocked, a payment confirmation arrives. The naive fix is a loop that keeps checking a flag, which burns CPU and races with the writer. std::condition_variable is the standard tool that lets a thread sleep until another thread wakes it, atomically tied to a mutex so no notification is lost. This chapter covers wait, wait_for, wait_until, notify_one, notify_all, spurious wakeups, and why the predicate form of wait isn't optional.