fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<future<void>> a;
  5.  
  6. void f() {
  7. cout << "started\n";
  8. a.push_back(std::async(std::launch::async,
  9. []() { std::this_thread::sleep_for(std::chrono::seconds(1)); }));
  10. cout << "finished\n";
  11. }
  12.  
  13. int main() {
  14. future<int> x = async([](){this_thread::sleep_for(chrono::seconds(1)); return 0;});
  15. future<int> y = async([](){this_thread::sleep_for(chrono::seconds(1)); return 1;});
  16. cout << x.get() << ' ' << y.get() << '\n';
  17. f();
  18. f();
  19. }
  20.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
0 1
started
finished
started
finished