in reply to Thread Safe alarms?
As alarm is usually implemented using signals (except on Windows, where signals don't exist), mixing threads and alarm is a bad idea (due to mixing threads and signals being a bad idea).
If you are on Windows, alarm is implemented by sending a Windows window timer message to the main thread. This won't interrupt long running operations in the main thread but will otherwise be threadsafe.
I would look again some more at the idea of the monitor thread, which monitors the execution (time) of the worker threads. Note that killing a thread also isn't really a nice thing to do, and can leave resources allocated until the main Perl process exits.
If you are on Unix, have you looked at Parallel::ForkManager and/or runN? On Windows, I would avoid fork (because it is, again, implemented using threads) in favour of system(1,@cmd), which launches a process separate from your main program.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Thread Safe alarms?
by Pocadotty (Initiate) on Apr 14, 2011 at 19:32 UTC | |
by BrowserUk (Patriarch) on Apr 14, 2011 at 20:16 UTC |