I am using linux machine with: clang version : 3.5.0 boost version : 1.68.0
i am using raspberry pi3 as my build machine. Twist is sometimes rpi3 system time is not in sync with the actual time and set to default value of 1 jan 1970. Now my project uses deadline timers for executing looping task using boost reactor loop and as per my logic as soon as rpi3 boots up my code (with deadline timer) should execute.
Example:
A code which logs entry every minute as soon as rpi3 boots up in the database.
problem here is when rpi3 system clock is not in sync with exact time it works fine but as soon as it gets synced with actual time my code crashes exactly at deadline timers.
I read and found that deadline timers give unexpected behaviour when system clock is adjusted : boost::deadline_timer can fail when system clock is modified
and for use cases like these we must use steady timers.
I did try that too but it shows same behaviour. Can someone throw some light whether i have implemented steady timer wrongly or i have mis understood the concept.
Below is my code :
boost::asio::basic_waitable_timer<boost::chrono::steady_clock> steadyWaitTimer(*io_service);
void loopFunction(){
boost::asio::basic_waitable_timer<boost::chrono::steady_clock, boost::asio::wait_traits<boost::chrono::steady_clock> >::duration loopingDuration(boost::chrono::seconds(60));
steadyWaitTimer.expires_from_now( loopingDuration );
int startWaitTime = std::time(0);
steadyWaitTimer.async_wait([this,startWaitTime](const boost::system::error_code &ec){
std::cout << " This async wait started at time : " << startWaitTime << " and ending at time : " << std::time(0) << std::endl << std::flush;
if(ec == boost::asio::error::operation_aborted){
std::cout<<"Operation aborted or say timer cancelled in asio task looper scheduleNext at time " << std::time(0) <<std::endl<<std::flush;
}
else {
std::cout << "Timer expired calling scheduleNext at time : " << std::time(0) <<"\n" << std::flush;
// want to go in loop till time is not synchronised
loopFunction();
}
});
}
Aucun commentaire:
Enregistrer un commentaire