Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > How to implemen...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 4057 of 4146
Post > Topic >>

How to implement an asynchronous timer in a multithreaded application

by "lali.cpp" <lali.cpp@[EMAIL PROTECTED] > Sep 26, 2008 at 05:13 AM

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
:)
 




 1 Posts in Topic:
How to implement an asynchronous timer in a multithreaded applic
"lali.cpp" <  2008-09-26 05:13:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 10:09:16 CST 2008.