fork download
  1. // thread example
  2. #include <iostream> // std::cout
  3. #include <thread> // std::thread
  4.  
  5. void foo()
  6. {
  7. // do stuff...
  8. }
  9.  
  10. void bar(int x)
  11. {
  12. // do stuff...
  13. }
  14.  
  15. int main()
  16. {
  17. std::thread first (foo); // spawn new thread that calls foo()
  18. std::thread second (bar,0); // spawn new thread that calls bar(0)
  19.  
  20. std::cout << "main, foo and bar now execute concurrently...\n";
  21.  
  22. // synchronize threads:
  23. first.join(); // pauses until first finishes
  24. second.join(); // pauses until second finishes
  25.  
  26. std::cout << "foo and bar completed.\n";
  27.  
  28. return 0;
  29. }
  30.  
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