fork download
  1. #include <iostream>
  2. #include <thread>
  3.  
  4. void doWork()
  5. {
  6. while(true)
  7. {
  8. // Do some work;
  9. sleep(1); // Rest
  10. std::cout << "hi from worker." << std::endl;
  11. }
  12. }
  13.  
  14. int main(int, char**)
  15. {
  16.  
  17. std::thread worker(&doWork);
  18. std::cout << "hello from main thread, the worker thread is busy." << std::endl;
  19. worker.join();
  20.  
  21. return 0;
  22. }
Time limit exceeded #stdin #stdout 5s 11216KB
stdin
Standard input is empty
stdout
hello from main thread, the worker thread is busy.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.
hi from worker.