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 ...

Get Mastering C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.