You can use std::this_thread::sleep_until , for example
void main() { auto fire_time = ; std::thread thread([&] { std::this_thread::sleep_until(fire_time); fire(); }); thread.join(); }
You can reorganize this into a helper function, which you are probably looking for:
template<class Func, class Clock, class Duration> void run_at(Func&& func, const std::chrono::time_point<Clock,Duration>& sleep_time) { std::thread(std::bind([&](const Func& func) { std::this_thread::sleep_until(sleep_time); func(); }, std::move(func))) .detach(); }
source share