How to install a reoccurring timer function?
问题 Is there a simple way to install a regularly occurring timer function with C++/stdlib? I would like to get rid of the loop: using namespace std::chrono; // literal suffixes auto tNext = steady_clock::now(); while (<condition>) { std::this_thread::sleep_until(tNext); tNext = tNext + 100ms; ... That function will run in its own thread. 回答1: I'm guessing what you want is this int i = 10; auto pred = [i]() mutable {return i--;}; auto print = []{cout << "." << endl;}; timer t{500ms}; t.push({print