Re: Yet another timers-and-threads question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Tim Ward" <tw2@xxxxxxxxxxxx> wrote in message
news:49htdeFodqvpU1@xxxxxxxxxxxxxxxxx
(snip)
Here's the desired model:

(1) There's a little mixin class called Timer which any class (window or
non-window) can inherit from.

(2) The class can then call setTimeout( seconds ) and killTimeout().

(3) When the timer expires the virtual function timeout() is called (I
don't
care in which thread, I can synchronise stuff if I have to).

the idea being to add timeouts to objects of any class running in any
thread
(ie GUI or non-GUI, which might wait on WaitForMultipleObejcts or recv or
absolutely anything else) in a couple of lines of code.

I think that is a fantastic idea. The main problem is having a thread that
is running some function, that can be interrupted. You have to add special
code to every function in every thread to know that it can be interrupted by
a timeout.

If your threads are always waiting, then add a new event that your
timer-window can signal, and have your thread wait on that event also. Of
course, this means that every timer for every thread would need a unique
event.

If your threads are compute-intensive and never waiting -- I believe you can
still use the above-mentioned event to signal the function. You would have
to make sure the threads computation runs in a tight loop that looks like
the following:
while (WaitForSingleObject(handleTimeoutEvent, 0) == WAIT_TIMEOUT)
{
// continue computation here
}

Good luck
DanB


.



Relevant Pages

  • Re: CreateTimerQueueTimer fails unexpectedly
    ... I send a command to a device and the device does not respond, ... So, in case of timeout I don't call shutdown, ... but a key point is that when the timer runs, ... written to deal with socket disconnect. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Serialport termios & timeout
    ... for VTIME and VMIN I can do it, ... If VTIME and VMIN are both greater than 0 the timer is ... and will timeout if there is the ...
    (comp.os.linux.development.apps)
  • Re: CreateTimerQueueTimer fails unexpectedly
    ... you should use stateless processing for both your IO completion and timeout logic. ... IOCP + timer queues is a good choice, but a key point is that when the timer runs, calling shutdown with SD_BOTH will abort any pending IO and trigger the cleanup logic you have already written to deal with socket disconnect. ... determine if a command has been responded in the desired time period. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: [update] Re: [RFC][PATCH] PM: Avoid losing wakeup events during suspend
    ... The kernel will still have to specify some small initial timeout. ... events_in_progress and the timer might simply decrement it. ... If a wakeup event it's just detected by one piece of code and is going to ... the timer expires. ...
    (Linux-Kernel)
  • Re: New "timeout" api, to replace callout
    ... existing timer, that means it wasn't close to firing and is moved ... session it has to be deallocated including stopping of all currently ... only ever grab the specified lock when it calls the timeout function. ... timeout data structures. ...
    (freebsd-arch)