Hi
I have a multi-threaded application. Currently i am using an
asynchronous timer. A thread registers a callback with that Timer and
when the timeout( i just need a single shot timer and not periodic)
occurs a callback function registered by the thread will be executed.
I can register upto 1000 timers with this Timer class.
The Timer is implemented as follows:
The Timer class consists of a single thread that loops infinitely
checking if a timeout occurs and then calls the callback of the
registered timer in a new thread( It itself doesn't execute the
callback function because it has to check for the timeouts of other
timers registered with this Timer class and hence spawns a new
thread( or take 1 from a thread pool ) and lets that thread execute
the call back function.
This will work fine if i register a limiter number of timers. But my
application needs a lot of timers to simulate calls and so i may need
to register about 1 milliion timers. So i guess the above
implementation is quite flawed in the current scenario as its my guess
that this timer won't be accurate.I don't need high precision timers
but just need accuracy in seconds i.e if i want timeout after 50
seconds, timeout at 50.5 seconds would be fine but 51 would be bad.
Also don't you think its a bad design as its non-deterministic in
nature ? I mean that would depend on when the scheduler schedules the
Timer thread on the CPU.
Am i too cautious ? Is my way of thinking wrong ?
How do you guys implement asynchronous timeouts ?
I am confused how to implement such a timer ?
Kindly help
:)