Multithreading: Condition Variables

This lesson elucidates best practices involving condition variables such as notify_one and notify_all in multithreaded applications in C++.

Condition Variables

Synchronizing threads via notifications is a simple concept, but condition variables make this task really challenging - mostly because the condition variables have no state.

  • If a condition variable gets a notification, it may be the wrong one spurious wakeup.
  • If a condition variable gets its notification before it was ready, the notification will be lost lost wakeup.

Don’t use condition variables without a predicate

Using a condition variable without a predicate is a race condition.

Get hands-on with 1400+ tech skills courses.