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

The following command helps you compile the program:

g++ main.cpp -std=c++17 -lpthread

In the previous command, -std=c++17 instructs the C++ compiler to enable the C++17 features; however, the program will compile on any C++ compiler that supports C++11, and you just need to replace c++17 with c++11.  

The output of the program will look like this:

All the numbers starting with 140 in the preceding screenshot are thread IDs. Since we created three threads, three unique thread IDs are assigned respectively by the pthread library. If you are really keen on finding the thread IDs assigned by the operating system, you will ...

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