I want to use Boost Deadline timer for a thread that will basically do work every 5 seconds. Simple enough, this is done. However, this thread will be spawned from a service that should be running 24/7, however, there will be times where the service may have to be restarted or taken offline for maintenance then restarted.
The problem: No matter what the current time is "now" I need the timer to do something every 5 seconds, from "on the hour".
What I mean is...
System starts up at 07:57:56 and the thread that will do work is started at this time. I don't want it to wait 5 seconds from
now and every 5 seconds because that will result in
07:58:01, 07:58:06 doing work. I need it to be
07:58:00, 07:58:05, 07:58:10 etc. So basically I need the first wait time to be the difference between "now" and whatever time is needed to "sync" it up as I have proposed.
Here is a sample of how this is being used:
1 2 3 4 5
|
void scheduler(const boost::system::error_code& , boost::asio::deadline_timer * t)
{
t->expires_at(t->expires_at() + boost::posix_time::seconds(5)); //This is ok once I'm in "sync" with the hour
t->async_wait(boost::bind(print, boost::asio::placeholders::error, t));
}
|
I'm just wondering what the best approach for this is, because I'm not sure the granularity of the expires_at() is. Is there a way to get it precise? Is there a "best way" to set this up.
Thanks.