foo:()={// simulate expensive operationstd::this_thread::sleep_for(std::chrono::seconds(1));}bar:()={// simulate expensive operationstd::this_thread::sleep_for(std::chrono::seconds(1));}main:()={std::cout<<"starting first helper...\n";helper1:std::jthread=(foo);std::cout<<"starting second helper...\n";helper2:std::jthread=(bar);std::cout<<"waiting for helpers to finish..."<<std::endl;helper1.join();helper2.join();std::cout<<"done!\n";}
Output
starting first helper...
starting second helper...
waiting for helpers to finish...
done!