#include #include #include using namespace std ; mutex mtx ; void thread_function1() { for( int i1=0 ; i1<5 ; i1++ ) { unique_lock lk( mtx ) ; cout << "Thread function1: " << i1 << endl ; } } void thread_function2() { for( int i1=0 ; i1<5 ; i1++ ) { unique_lock lk( mtx ) ; cout << "Thread function2: " << i1 << 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; }