Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] deadline_timer makes wrong delay when using date command
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-09-07 09:03:00


Am Monday 07 September 2009 13:24:58 schrieb Bjarne Laursen:
> I have used a deadline_timer to generate a polling every 1 second.
> Unfortunely when I use the linux date command the timing is curupted. (If
> I set the clock back 1 min. I will be missing 60 pollings).
> What can I do about that?
> -Bjarne

I don't know how to solve that within asio but I also needed a timer like that
and didn't want to create a dependency on asio just for that, so I'm using
the following for now, which should also solve your problem (if you don't
also use asio for other purposes):

class cache_timer{
public:
        cache_timer(...)
                : resolution(...)
                , thread(boost::bind(&cache_timer::run,this))
{} //throw(thread_resource_error)
        void run(){
                while(!this_thread::interruption_requested()){
                        this_thread::sleep(resolution);
                        ...
                }
        }
        ~cache_timer(){ //throw()
                this->thread.interrupt();
                this->thread.join();
        }
private:
        posix_time::time_duration resolution;
        boost::thread thread;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net