Hi
I am implementing an asynchronous timer, would like to build
it similar to the one included in the asio library. I am using a timer wheel
implementation i.e a fixed size array of double linked lists.
The timer wheel implementation is quite efficient as
insertion is O(1), deletion of timer is O(1) and firing of timer is also O(1).
The only drawback is that the time registered should not be greater than the
size of 1 rotation of the wheel.
typedef list<Timer> ListOfTimers
ListOfTimers myTimerobj(10000) ( with 100 ticks
per second this would give an accuracy of 10ms )
The thread in the timer delegates the execution of the
callbacks to another thread ( take from a thread pool ).
From what I have read from the code of timer in asio
library, I guess its implemented as a heap. But in a heap data structure (implemented
as vector ), insertion and deletion would be O(lg n) I would like to know
the reason to use heap. This is purely for educational purpose so that I can
understand the design rationale. Also I would like to know that would boost::asio
asynchronous timer be efficient for say 200000 timers firing at the same time ?
I also wish to implement a timer similar to one in boost::asio, purely for
knowledge. I need this in my application in which I would thousands of timers
firing at the same time.
Can someone provide some design details of boost::asio timer
implementation so that I can build a timer similar to that. ( It would make it
easy for me to read the code provided by boost::asio if I know the design
rationale)
Please don’t get offended if you find the above post
irrelevant in this mailing list J
Here is the very simple interface I am implementing.
Here is the API I wish to implement( I would like to see
comments on what else should be the public interface of such a class )
TimerHandle registerTimer(period,callBackFunctor)
void cancelTimer(TimerHandle)
int timeElapsed(TimerHandle)
int timeLeft(TimerHandle)
Thanks & Regards
Kartik Mahajan