#include #include #include using namespace std ; recursive_mutex myRecursiveMutex; void function2( int thread_id ) { unique_lock lock(myRecursiveMutex); cout << "function2: with thread id of:" << thread_id << endl ; } void function1( int thread_id ) { cout << "function1: with thread id of:" << thread_id << endl ; myRecursiveMutex.lock(); for( int i1=1; i1<=5 ; i1++ ) { function2( thread_id ) ; } } int main() { thread t1( function1, 1 ); //this_thread::sleep_for(chrono::milliseconds(10)); thread t2( function2, 2 ); t1.join(); t2.join(); return 0; }