Condition Variables

In this lesson, we will see how tasks should be your first choice when using multithreading.

Introduction

Condition variables enable threads to be synchronized via messages.

They need the <condition_variable> header.

One thread acts as a sender, and the other acts as the receiver of the message. The receiver waits for a notification from the sender. Typical use cases for condition variables are sender-receiver or producer-consumer workflows.

A condition variable can be the sender or the receiver of the message.

The following table details the different condition variables and their respective functions.

Get hands-on with 1200+ tech skills courses.