fork(4) download
  1. #include <iostream>
  2. #include <future>
  3. #include <chrono>
  4. using namespace std;
  5.  
  6. template <class F>
  7. void call_async(F&& fun) {
  8. thread_local char buf[sizeof(std::future<void>)] = {0};
  9. auto fut = new(buf) std::future<void>();
  10. *fut = std::async(std::launch::async, [fun]() {
  11. fun();
  12. });
  13. }
  14.  
  15. void f()
  16. {
  17. std::this_thread::sleep_for(10ms);
  18. cout << "LOL" << endl;
  19. }
  20.  
  21. int main()
  22. {
  23. cout << "KEK" << endl;
  24. call_async(f);
  25. cout << "OMG" << endl;
  26. std::this_thread::sleep_for(100ms);
  27. }
Success #stdin #stdout 0s 4780KB
stdin
Standard input is empty
stdout
KEK
OMG
LOL