#include #include #include using namespace::std; // gcc -std=c++11 thread_1.cc -lstdc++ -o thread_1 std::mutex mu; void shared_print(string msg,int id) { std::lock_guard guard(mu); // RAII - when guard goes out of scope //mu.lock(); // if cout throws an exception then the program will be locked forever. cout << msg << id << endl; // still could mess up output if other process writes to cout. //mu.unlock(); } void fun1() { cout << "Im in function 1"<-10;i--) // cout << msg << i <