Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ace-users] Antwort: RE: ACE timers dependend on absolute system time

45 views
Skip to first unread message

Christian...@rohde-schwarz.com

unread,
Mar 29, 2010, 3:21:43 AM3/29/10
to shu...@riverace.com, ace-...@list.isis.vanderbilt.edu

Hi Steve,

thanks a lot. That solved our problem.

These two lines (taken from the book) could fix the problem for the whole application:
ACE_Reactor *r = ACE_Reactor::instance ();
r->timer_queue ()->
 gettimeofday (&ACE_High_Res_Timer::gettimeofday_hr);


Best regards,
Chris



"Steve Huston" <shu...@riverace.com>

26.03.2010 21:14

An
<Christian...@rohde-schwarz.com>, <ace-...@list.isis.vanderbilt.edu>
Kopie
Thema
RE: [ace-users] ACE timers dependend on absolute system time





Hi Christian,
 
You can check out use of the ACE_High_Res_Timer::gettimeofday_hr() to replace the default time source in the timer queue. There's an example in C++NPv2 section 3.4 which is explained further in Sidebar 14.
 
For more info, on C++NPv2, http://www.riverace.com/acebooks/index.htm#cnpv2
 
If follow-up questions arise, please use the PROBLEM-REPORT-FORM.
 
-Steve

--
Steve Huston, Riverace Corporation
Total Lifecycle Support for Your Networked Applications

http://www.riverace.com

-----Original Message-----
From:
ace-user...@list.isis.vanderbilt.edu [mailto:ace-user...@list.isis.vanderbilt.edu] On Behalf Of Christian...@rohde-schwarz.com
Sent:
Friday, March 26, 2010 2:56 PM
To:
ace-...@list.isis.vanderbilt.edu
Subject:
[ace-users] ACE timers dependend on absolute system time


Hi,


we are making heavy use of ACE timers using the ACE_Thread_Timer_Queue_Adapter template on several Windows platforms.


Our problem is that these timer heavily depend on the absolute system time. As I understand it, a timer event is scheduled "for some time in the future". But when the system clock is changed, the effect is that handle_timeout is either called too fast (when system clock is moved forward), or not called at all for a longer time (when the system clock is moved backward). The former sometimes causes our software to run into timeout situations even when everything is OK. The latter causes out watchdogs to time out since keep-alive messages are not scheduled in time.


Is there some replacement timer in the ACE framework that only relies on relative times? I am thinking of something which works like WM_TIMER message in Windows.


I know I could build my own active timer task simple by creating an ACE task which runs an endless loop sleeping for some seconds and then calling a timeout callback. But how could I inject this class into ACE method that take a timeout value (e. g. ACE_Connector::connect)?


Here is some sample code showing what we are doing:


#include
<iostream>
#include
<ace/Event_Handler.h>
#include
<ace/OS.h>
#include
<ace/Reactor.h>
#include
<ace/Time_Value.h>
#include
<ace/Timer_Heap.h>
#include
<ace/Timer_Queue_Adapters.h>

int
_startTickCount = ::GetTickCount();

class
MyEventHandler : public ACE_Event_Handler
{

 
virtual int handle_timeout(const ACE_Time_Value& current_time, const void* act)
 {

   ACE_Time_Value now(ACE_OS::gettimeofday());

   std::cout << __FUNCTION__
             <<
", TickCount: " << (::GetTickCount() - _startTickCount) / 1000
             <<
", TimeOfDay: " << now.sec()
             << std::endl;

   
return 0;
 }

};


void
run()
{

 MyEventHandler eventHandler;

 
 
typedef ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Heap> ActiveTimer;
 ActiveTimer timer;

 
const ACE_Time_Value delay(5);
 timer.schedule(&eventHandler, NULL, delay, delay);

 timer.activate();


 ACE_Reactor::instance()->run_reactor_event_loop();

}


int
_tmain(int argc, _TCHAR* argv[])
{

 ACE::init();

 run();

 ACE::fini();

 
return 0;
}


Thanks for any ideas,
Chris

0 new messages