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.
In reply to Re: Thread Safe alarms?
by Corion
in thread Thread Safe alarms?
by Pocadotty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |