fork download
  1. #include <iostream>
  2. #include <thread>
  3. #include <chrono>
  4.  
  5. void performTenTimes(std::function<void()> const& f)
  6. {
  7. int counter = 10;
  8. std::chrono::milliseconds s(10);
  9. while(counter--) {
  10. f();
  11. std::this_thread::sleep_for(s);
  12. };
  13. }
  14.  
  15. int main() {
  16. auto f = []() { std::cout << "Task\n"; };
  17. std::thread t(performTenTimes, f);
  18. t.join();
  19.  
  20. return 0;
  21. }
  22.  
Runtime error #stdin #stdout #stderr 0s 3428KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::system_error'
  what():  Enable multithreading to use std::thread: Operation not permitted