Re: Yet another timers-and-threads question
- From: "Dan Baker" <dbmail>
- Date: Wed, 5 Apr 2006 09:03:56 -0600
"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
.
- Follow-Ups:
- Re: Yet another timers-and-threads question
- From: Tim Ward
- Re: Yet another timers-and-threads question
- References:
- Yet another timers-and-threads question
- From: Tim Ward
- Yet another timers-and-threads question
- Prev by Date: Re: multidimensional CStringarray
- Next by Date: Re: MFC vs Win32 programming
- Previous by thread: Re: Yet another timers-and-threads question
- Next by thread: Re: Yet another timers-and-threads question
- Index(es):
Relevant Pages
|