fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. using namespace std;
  5.  
  6. void thread1()
  7. {
  8. while(true)
  9. {
  10. this_thread::sleep_for(chrono::milliseconds(300)); // Симуляция работы
  11. // здесь нужна синхронизация с другими потоками
  12. }
  13. }
  14.  
  15. void thread2()
  16. {
  17. while(true)
  18. {
  19. this_thread::sleep_for(chrono::milliseconds(500)); // Симуляция работы
  20. // здесь нужна синхронизация с другими потоками
  21. }
  22. }
  23.  
  24. int main()
  25. {
  26. thread t1(thread1);
  27. thread t2(thread2);
  28.  
  29. t1.detach();
  30. t2.detach();
  31.  
  32. // thread 0
  33. while(true)
  34. {
  35. this_thread::sleep_for(chrono::milliseconds(100)); // Симуляция работы
  36. // здесь нужна синхронизация с другими потоками
  37. }
  38. }
Runtime error #stdin #stdout #stderr 0s 3472KB
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