Overview
Features
Download
Documentation
Community
Add-Ons & Services

Poco::Timer bug for long startInterval/periodic interval

Please post support and help requests here.

Poco::Timer bug for long startInterval/periodic interval

Postby budric » 16 Jun 2009, 20:17

When the interval value is multiplied by 1000 to convert to microseconds, the long variable overflows. For example a periodic timer that calls back every hour = 3,600,000 ms, the code _nextInvocation += interval*1000; overflows. Then inside Timer::run() sleep is < 0 because you've added a negative value to _nextInvocation, sleep is set to 0 causing the timer to call callback repeatedly.

One possible fix is to use 64 bit variable to calculate _nextInvocation. I modified the following functions:
Code: Select all
void Timer::start(const AbstractTimerCallback& method, Thread::Priority priority, ThreadPool& threadPool)
{
-       nextInvocation += _startInterval*1000;
+   nextInvocation += (Poco::Timestamp::TimeVal)(_startInterval)*1000;
}

void Timer::run()
{
-    long interval(0)
+    Poco::Timestamp::TimeVal interval(0);
}
budric
 
Posts: 24
Joined: 13 May 2009, 17:14

Re: Poco::Timer bug for long startInterval/periodic interval

Postby guenter » 17 Jun 2009, 08:17

guenter
 
Posts: 1121
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Poco::Timer bug for long startInterval/periodic interval

Postby budric » 17 Jun 2009, 16:27

I see someone fixed it in the 1.3.6 trunk. Thanks for the quick handling of the problem.
budric
 
Posts: 24
Joined: 13 May 2009, 17:14


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron