Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Perl how to join all threads

by sundialsvc4 (Abbot)
on Jul 07, 2015 at 17:39 UTC ( [id://1133580]=note: print w/replies, xml ) Need Help??


in reply to Perl how to join all threads

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133580]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found