[chuck-users] implementing a "wait for signal with timeout"
rdpoor at gmail.com
Mon Jun 8 17:45:36 EDT 2009
So as presaged, this is a schematic of how I've implemented "wait for
signal or timeout".
First, I have a "PermaShred" class: a call to:
calls a do_process() function (which you subclass) in its own thread,
er, shred. When your do_process() function returns, the shred is
returned to a resource pool, making it available to the next call to
PermaShred.run_process(). That's my basic mechanism for not leaking
To build wait_for_signal_or_timeout(event E, time T) functionality, I
spawn, er, spork a PermaShred "watchdog" that waits until time T
arrives, and then does a E.broadcast(). In the meantime, the caller
simply blocks on event E. As a result, the caller will return if
anyone does a broadcast on E OR if the watchdog process times out.
It's a bit convoluted -- among other nuances, the watchdog shred needs
to be careful about signaling after the caller has moved on -- but it
does the job. And it doesn't leak memory after an initial pool of
PermaShred objects have been allocated.
If anyone wants to see the code, let me know.
More information about the chuck-users