fork(4) download
  1. #include <iostream>
  2. #include <thread>
  3. #include <future>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8.  
  9.  
  10. std::promise<int> promise_that_data_is_loaded;
  11. auto loaded_future = promise_that_data_is_loaded.get_future();
  12. std::thread t([&promise_that_data_is_loaded]()
  13. {
  14. int i =0;
  15. while (i < 100)
  16. {
  17. ++i;
  18. }
  19. promise_that_data_is_loaded.set_value(i); //set this after work is done
  20. });
  21. long long int tm = 0;
  22. while(loaded_future.wait_for(std::chrono::seconds(1)) != std::future_status::ready)
  23. {
  24. tm++;
  25. }
  26. cout << tm <<endl;
  27. loaded_future.get();
  28. t.join();
  29. return 0;
  30. }
Success #stdin #stdout 0s 17304KB
stdin
Standard input is empty
stdout
0