#include #include #include #include std::mutex cout_mutex { }; void task_A() { auto id = std::this_thread::get_id(); cout_mutex.lock(); std::cout << "My ID: " << id << std::endl; cout_mutex.unlock(); } void task_B(std::string const& message) { cout_mutex.lock(); std::cout << message << std::endl; cout_mutex.unlock(); } int main() { std::thread t1 { task_A }; std::thread t2 { task_B, "A message from t2" }; cout_mutex.lock(); std::cout << "Starting!" << std::endl; cout_mutex.unlock(); t1.join(); t2.join(); }