// compile: g++ -std=c++17 -pthread threads1.cpp #include #include #include using namespace std::chrono_literals; // s as second void foo() { std::cout<<"started foo\n"; std::this_thread::sleep_for(3s); } void bar(int x) { std::cout<<"started bar\n"; std::this_thread::sleep_for(5s); } int main() { std::thread th1 (foo); // a thread calls foo() std::thread th2 (bar,0); // a thread calls bar(0) th1.join(); // wait for th1 to finish std::cout<<"th1 joins\n"; th2.join(); // wait for th2 to finish std::cout<<"th2 joins\n"; }