O'Reilly logo

Mastering C++ Programming by Jeganathan Swaminathan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to compile and run

Compile the program with the following command:

g++ Thread.cpp main.cpp -o conditional_variable.exe -std=c++17 -lpthread

The following snapshot demonstrates the output of the program:

Great! Our condition variable demo works as expected. The producer and consumer threads are working together cooperatively with the help of a conditional variable.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required