[asio] deadline_timer makes wrong delay when using date command
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 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?
Do you use expire_from_now()?
On Mon, 07 Sep 2009 13:33:25 +0200, Igor R
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?
Do you use expire_from_now()?
Well I did not. I used expires_at(expires_at() + TIMETOADD); because that is the behaviour that is specified for the timer function that I'm implementing. but I have just tested expire_from_now(). And it does the exact same thing.
Well I did not. I used expires_at(expires_at() + TIMETOADD); because that is the behaviour that is specified for the timer function that I'm implementing.
but I have just tested expire_from_now(). And it does the exact same thing.
Probably something like this would help: expires_at(ptime::microsec_clock::universal_time() + TIMETOADD);
On Mon, 07 Sep 2009 16:11:56 +0200, Igor R
Probably something like this would help: expires_at(ptime::microsec_clock::universal_time() + TIMETOADD);
I tried the following (asuming that it was what you ment): void GMyTask::OnAsioTimer() { std::cout << "Tick" << std::endl; m_AsioTimer.expires_at(boost::posix_time::microsec_clock::universal_time() + boost::posix_time::millisec(1000)); m_AsioTimer.async_wait(boost::bind(&GMyTask::OnAsioTimer, this)); } Problem remains the same.
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; };
On Mon, 07 Sep 2009 15:03:00 +0200, Stefan Strasser
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.
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
One unorthodox solution would be to run NTP (www.ntp.org) on your servers. This will keep the time in sync. There should be no need for changing time on the system. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
On Tue, 08 Sep 2009 14:06:28 +0200, Ray Burkholder
One unorthodox solution would be to run NTP (www.ntp.org) on your servers. This will keep the time in sync. There should be no need for changing time on the system.
I guess that some of my customers will indeed run NTP, or some other automatic adjustment. But only occasionally when the system is connected during service. Even then, I think that it wound get a very accurate clock source. The service tool is probably a laptop, not connected to anything else during the service. Then when NTP adjust the clock we have the problem. But it's not just me. asio is a library for everyone it should behave better. I still hope to learn how to make it do that. (Although it should be default). After all, windows have timers like GetTickCount and QuaryPerformanceCounter, on Linux I think times() could be used to get a continuous nonjumping clock. A clock like that is what we need to make small timeouts for communication purposes. -Bjarne
I made a solution for this. See https://svn.boost.org/trac/boost/ticket/3504
participants (4)
-
Bjarne Laursen
-
Igor R
-
Ray Burkholder
-
Stefan Strasser