Forcing Order between Threads

The condition_variable class is a synchronization primitive that can be used to block a thread, or multiple threads at the same time, until another thread both modifies a shared variable (the condition), and notifies the condition_variable 1. atomic template defines an atomic type. If one thread writes to an atomic object while another thread reads from it, the behavior is well-defined 2 (see memory model 3 for details on data races).

More …

Producer-Consumer Problem in C++

Used mutex and condition_variable. While using them, I utilized unique_lock class that provides a flexible way to lock/unlock mutexes and control condition variables. ```c++ #include #include #include #include #include

More …