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