I see that we have a deadline timer in boost. I am looking for a periodic
timer. I see that there is a sample code in boost website to simulate a
periodic timer. Over a period of time I think it will probably cause some
slippage. I am looking at microsecond granularity Can someone please advise?
#include <iostream>
#include
void print1() { if (count_ < 100) { timer1_.expires_at(timer1_.expires_at() + boost::posix_time::microseconds(10)); timer1_.async_wait(boost::bind(&printer::print1, this)); std::cout << "Timer 1: " << count_ << "\n"; ++count_;
}
Over a period of time I think it will probably cause some slippage.
This is because you always take a new "reference time". I guess that if you store the initial reference-point (when starting the timer for the 1st time) and then always add to *it* a time_duration*iterationNumber, then the slippage wouldn't accumulate.
Also, wouldn't the function call itself have an overhead? If yes, is there a
way to get around it ?
On Tue, Sep 9, 2008 at 5:10 PM, Igor R
void print1() { if (count_ < 100) { timer1_.expires_at(timer1_.expires_at() + boost::posix_time::microseconds(10)); timer1_.async_wait(boost::bind(&printer::print1, this)); std::cout << "Timer 1: " << count_ << "\n"; ++count_;
}
Over a period of time I think it will probably cause some slippage.
This is because you always take a new "reference time". I guess that if you store the initial reference-point (when starting the timer for the 1st time) and then always add to *it* a time_duration*iterationNumber, then the slippage wouldn't accumulate. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- ------------------------------------------------------------------- Ph : (732) 647 5679 Email: khandelwal.amit@gmail.com Web: http://khandelwal.amit.googlepages.com/home -------------------------------------------------------------------
Also, wouldn't the function call itself have an overhead? If yes, is there a way to get around it ?
Well, there exists some overhead at each "iteration", but if you've got a fixed reference-time, these overheads wouldn't accumulate, so after 2 or 1000 iterations you'd have about the same deviation. As for the deviation itself, you just have to try and evaluate it with your compiler/machine...
Thanks for your help
On Wed, Sep 10, 2008 at 7:12 AM, Igor R
Also, wouldn't the function call itself have an overhead? If yes, is there a way to get around it ?
Well, there exists some overhead at each "iteration", but if you've got a fixed reference-time, these overheads wouldn't accumulate, so after 2 or 1000 iterations you'd have about the same deviation. As for the deviation itself, you just have to try and evaluate it with your compiler/machine... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- ------------------------------------------------------------------- Ph : (732) 647 5679 Email: khandelwal.amit@gmail.com Web: http://khandelwal.amit.googlepages.com/home -------------------------------------------------------------------
participants (2)
-
amit khandelwal
-
Igor R