fork download
  1. #include <chrono>
  2. #include <condition_variable>
  3. #include <iostream>
  4. #include <memory>
  5. #include <mutex>
  6. #include <stdexcept>
  7. #include <thread>
  8.  
  9.  
  10. struct Blocker
  11. {
  12. Blocker() :
  13. wait_thread([this]() {
  14. std::mutex mtx;
  15. std::unique_lock<std::mutex> lck(mtx);
  16. cond.wait(lck);
  17. })
  18. {
  19. }
  20.  
  21. void wait()
  22. {
  23. wait_thread.join();
  24. }
  25.  
  26. void notify()
  27. {
  28. cond.notify_one();
  29. }
  30.  
  31. std::condition_variable cond;
  32. std::thread wait_thread;
  33. };
  34.  
  35.  
  36. template<typename Callback>
  37. void async_operation(const Callback & cb) { cb(); }
  38.  
  39.  
  40. int main()
  41. {
  42. Blocker b;
  43. async_operation([&](){ b.notify(); });
  44. b.wait();
  45.  
  46. std::cout << "End of program." << std::endl;
  47. }
Time limit exceeded #stdin #stdout 5s 11216KB
stdin
Standard input is empty
stdout
Standard output is empty