#include #include #include using namespace std ; mutex mutex1 ; mutex mutex2 ; void thread_function1() { cout << "Enter Thread function1: " << endl ; mutex1.lock() ; this_thread::sleep_for(chrono::milliseconds(1000)); mutex2.lock() ; mutex1.unlock() ; mutex2.unlock() ; cout << "Exiting Thread function1: " << endl ; } void thread_function2() { cout << "Enter Thread function2: " << endl ; mutex2.lock() ; this_thread::sleep_for(chrono::milliseconds(1000)); mutex1.lock() ; mutex2.unlock() ; mutex1.unlock() ; cout << "Exiting Thread function2: " << endl ; } int main() { thread t1( &thread_function1 ); // t1 starts running thread t2( &thread_function2 ); // t2 starts running //cout << "main thread\n"; // main thread waits for the thread t1 to finish t1.join(); t2.join(); return 0; }