concurrency

Using a condition variable in C++

A condition variable (std::condition_variable from the <condition_variable> header) is an abstraction allowing for one or multiple threads to wait on an event associated with modification of some shared variable. As an example, consider two threads, denoted the publisher and the subscriber. The former generates a series of events, with some associated data. The latter subscribes to these events and processes the data elements as they become available. For making this possible, we will use the global mutex and condition variable: