Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] deadline_timer makes wrong delay when using date command
From: Bjarne Laursen (bla_at_[hidden])
Date: 2009-09-08 01:46:32


On Mon, 07 Sep 2009 15:03:00 +0200, Stefan Strasser
<strasser_at_[hidden]> wrote:

> 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;
> };

Thank you for the code. The thing is that I'm porting a central part of
rather large amount of code from windows (MSVC6) into a multi target
system, where the main target is linux.

The original code use a combination of WaitForMultipleObjectsEx and
GetTickCount to make a common destribution point for incoming data and
timers.
In addion a few user-modules used a function to give a CEvent and have my
framework call a member function if the event becomes set. It is typical
used to handle file/network/serial i/o, in windows.

I have now implemented the use of asio for this central waiting point and
it seem work well. Except for this problem. (And the shut down sequence,
but thats another issue I need to work with)

I don't know if the original windows system suffers from this problem
also, but I need to come up with a solution on the new.

Even if I need to give up the use of deadline_timer, I probably will
continue to use asio. I just thought that I had missed some simple setup
somewhere. It seem that the typical use of timers in asio (and given in
examples) is to make timeout for i/o operations. And as I see it, the use
of the date command will almost always make a program using asio fail.


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