fork(2) download
  1. #include <future>
  2. #include <chrono>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. using namespace std::chrono;
  7.  
  8. int main()
  9. {
  10. const auto start_time = steady_clock::now();
  11.  
  12. async(launch::async, [] { this_thread::sleep_for(seconds(2)); });
  13. async(launch::async, [] { this_thread::sleep_for(seconds(2)); });
  14. auto f = async(launch::async, [] { this_thread::sleep_for(seconds(2)); });
  15. f.wait();
  16.  
  17. const auto end_time = steady_clock::now();
  18.  
  19. cout << duration_cast<milliseconds>(end_time - start_time).count() << '\n';
  20. }
  21.  
Success #stdin #stdout 0s 4268KB
stdin
Standard input is empty
stdout
6000