fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <thread>
  4. using namespace std;
  5.  
  6. void timer_start(function<void(void)> func, unsigned int interval)
  7. {
  8. thread([func, interval]() {
  9. while (true)
  10. {
  11. func();
  12. this_thread::sleep_for(chrono::milliseconds(interval));
  13. }
  14. }).detach();
  15. }
  16.  
  17. void produktion()
  18. {
  19. cout << "tick" << endl;
  20. }
  21.  
  22. int main() {
  23.  
  24. timer_start(produktion, 100);
  25.  
  26. this_thread::sleep_for(chrono::milliseconds(1000));
  27. return 0;
  28. }
Success #stdin #stdout 0s 11656KB
stdin
Standard input is empty
stdout
tick
tick
tick
tick
tick
tick
tick
tick
tick
tick