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

You can use the following command to compile this program:

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

Observe the output of the program, as follows:

Refer to the code snippets of the Thread::getCount() and Thread::updateCount() methods:

int Thread::getCount() {         cout << name << " is waiting for lock in getCount() method ..." << endl;         lock_guard<mutex> locker(commonLock);         cout << name << " has acquired lock in getCount() method ..." << endl;         return count;}int Thread::updateCount() {        count << name << " is waiting for lock in updateCount() method ..." << endl;        lock_guard<mutex> locker(commonLock); cout ...

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