We don't bite newbies here... much | |
PerlMonks |
Re: Perl how to join all threadsby sundialsvc4 (Abbot) |
on Jul 07, 2015 at 17:39 UTC ( [id://1133580]=note: print w/replies, xml ) | Need Help?? |
Also note one of BrowserUK’s comments, found in the “do not mix” thread cited above, that you can sometimes just detach the threads and let them go. You do not need to join with them unless you need to know that they have all terminated. As a categorical rule-of-thumb, do not attempt to do anything within a signal handler, because you have no way to know precisely what was going on at the time the signal was received. (Although the Perl interpreter will safely maintain its own internal state.) Your handler should only raise some kind of yellow-flag, and maybe nudge threads that might be dozing so that they will see that the flag has been raised and they can react to it. Time-consuming loops should include tests of the flag and break out of the loop. (Another way to do it is to throw an exception.) Only the main thread should be relied-upon to receive and act on the signal. The flag itself (as shown elsewhere) must be thread-safe. The signal handler may be called any number of times. The signal should immediately cause some kind of acknowledgement message to be printed (to STDERR) so that the user will know that the program heard the bell ring. The user should then see additional messages that show that it is, in fact, winding-up its affairs and shutting down.
In Section
Seekers of Perl Wisdom
|
|