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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|