fork download
  1. #include <iostream>
  2. #include <future>
  3.  
  4. int main() {
  5. int x = 2;
  6. auto p = [&] { std::cout << "got this far!"; std::cout.flush(); x = 4; };
  7. try {
  8. auto h = std::async(std::launch::async,p);
  9. int j = 0;
  10. for (int i = 0; i < 10000; i++)
  11. if (x == 4) std::cout << "YEAH!";
  12. j++;
  13. }
  14. catch(std::system_error &ex) {
  15. std::cout << ex.code();
  16. }
  17.  
  18. }
Success #stdin #stdout 0s 2980KB
stdin
Standard input is empty
stdout
generic:1