fork(1) download
  1. #include <thread>
  2. #include <atomic>
  3. #include <chrono>
  4. #include <iostream>
  5.  
  6.  
  7. std::atomic_bool stop_thread;
  8. std::thread thd;
  9.  
  10. int main()
  11. {
  12. thd = std::thread([]{
  13. while ( ! stop_thread.load() )
  14. std::this_thread::sleep_for(std::chrono::milliseconds(200));
  15. atexit([] { std::cout << "Exit thread\n"; });
  16. });
  17.  
  18. atexit([]{
  19. stop_thread.store(true);
  20. thd.join();
  21. });
  22.  
  23. std::cout << "Exiting\n";
  24. return 0;
  25. }
  26.  
  27.  
Success #stdin #stdout 0s 17296KB
stdin
Standard input is empty
stdout
Exiting
Exit thread