in reply to Threads Timeout
The basic idea here is definitely the right approach: let the thread set a timeout upon itself, so that when 31 seconds arrive ... the thread does not keep going, wasting CPU time to produce a result that will never be interesting. Instead, it dies. This is much more reliable in-practice than having a separate process out there with a stopwatch in its hands, which is quite vulnerable to edge-case race conditions. Let each thread be fully responsible for its own outcome, whatever that may be, and for dealing with it and for reporting it.
The only thing that I do not see here (having only glanced at the responses most casually and briefly, is that usually the thread, before dying, needs to in some way signal a waiting parent that it has failed. Perhaps the final-status of the thread is enough to do that, or you might need to add code to send some kind of a message to someone (perhaps, to a process that isn’t the parent) to the effect that such-and-such a unit of work could not be completed timely. Several ways to tackle that, of course ... maybe the parent does it, and maybe not ... and mind you, I’m not suggesting that the solutions offered here so-far do not work because they most clearly do.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Threads Timeout
by BrowserUk (Patriarch) on Jan 23, 2012 at 19:44 UTC | |
by locked_user sundialsvc4 (Abbot) on Jan 24, 2012 at 14:55 UTC | |
by BrowserUk (Patriarch) on Jan 24, 2012 at 15:30 UTC |