#include #include #include using namespace std ; mutex mtx ; void thread_function1() { for( int i1=0 ; i1<5 ; i1++ ) { // Pre C++ 11 //lock_guard lk( mtx ) ; //With C++ 17 lock_guard lk( mtx ) ; cout << "Thread function1: " << i1 << endl ; } } int main() { thread t1( &thread_function1 ); // t1 starts running //cout << "main thread\n"; // main thread waits for the thread t1 to finish t1.join(); return 0; }