fork download
  1. #include <iostream>
  2. #include <thread>
  3. #include <atomic>
  4. #include <chrono>
  5. #include <string>
  6. using namespace std;
  7.  
  8. void timer(atomic<bool>& stop)
  9. {
  10. unsigned cnt = 0;
  11. while (this_thread::sleep_for(1s), stop == false)
  12. {
  13. cerr << (++cnt) << endl;
  14. }
  15.  
  16. cerr << "Timer's stopped" << endl;
  17. }
  18.  
  19. int main()
  20. {
  21. atomic<bool> stop{false};
  22.  
  23. thread t{timer, ref(stop)};
  24.  
  25. string s;
  26.  
  27. while (cin >> s, s != "stop")
  28. {
  29. cout << "echo " << s << endl;
  30. }
  31.  
  32. stop.store(true);
  33. t.join();
  34. return 0;
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
ala
ma
kota
stop
compilation info
/home/WoF7Nf/ccAEIvzc.o: In function `std::thread::thread<void (&)(std::atomic<bool>&), std::reference_wrapper<std::atomic<bool> > >(void (&)(std::atomic<bool>&), std::reference_wrapper<std::atomic<bool> >&&)':
prog.cpp:(.text._ZNSt6threadC2IRFvRSt6atomicIbEEISt17reference_wrapperIS2_EEEEOT_DpOT0_[_ZNSt6threadC5IRFvRSt6atomicIbEEISt17reference_wrapperIS2_EEEEOT_DpOT0_]+0x2): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty