What is the difference between a condition variable and busy-waiting? How does std::condition_variable work?

Last updated 21 June 2026

  • Busy-waiting spins in a loop (e.g. while(!ready){}) checking a condition, burning a CPU core. It is only worth it for extremely short waits.

  • A std::condition_variable puts the thread to sleep (zero CPU) until another thread calls notify_one() or notify_all() after changing shared state.

  • It pairs with a std::mutex: wait() atomically releases the lock, sleeps, and reacquires on wakeup. Always check a predicate in a loop (or use the predicate overload) to handle spurious wakeups.

  • https://www.geeksforgeeks.org/cpp/cpp-multithreading-condition-variables/
  • https://github.com/mobelus/CppSamples
  • https://github.com/eyedol/tools/blob/master/anki-card.csv
  • https://www.geeksforgeeks.org/operating-systems/synchronization-concurrency-interview-questions/
All C++ interview questions