summaryrefslogtreecommitdiff
path: root/pod/perlthrtut.pod
diff options
context:
space:
mode:
authorjohnh@isi.edu <johnh@isi.edu>2007-12-05 01:45:40 -0800
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2007-12-12 09:48:09 +0000
commit2faf59db7dd6574a1e9d7826c0c5873e9bf0a671 (patch)
treebf59a767de550ad1579328724267a8fa9d55dcec /pod/perlthrtut.pod
parente67ed6948b0e6164946ef34f55b86ed0976bc4ff (diff)
downloadperl-2faf59db7dd6574a1e9d7826c0c5873e9bf0a671.tar.gz
[perl #48214] documentation enhancement to perlthrtut
From: johnh@isi.edu (via RT) <perlbug-followup@perl.org> Message-ID: <rt-3.6.HEAD-28750-1196876739-1770.48214-75-0@perl.org> p4raw-id: //depot/perl@32612
Diffstat (limited to 'pod/perlthrtut.pod')
-rw-r--r--pod/perlthrtut.pod30
1 files changed, 30 insertions, 0 deletions
diff --git a/pod/perlthrtut.pod b/pod/perlthrtut.pod
index be4954529f..e1acf6d190 100644
--- a/pod/perlthrtut.pod
+++ b/pod/perlthrtut.pod
@@ -323,6 +323,36 @@ detach itself:
# Do more work
}
+=head2 Process and Thread Termination
+
+With threads one must be careful to make sure they all have a chance to
+run to completion, assuming that is what you want.
+
+An action that terminates a process will terminate I<all> running
+threads. die() and exit() have this property,
+and perl does an exit when the main thread exits,
+perhaps implicitly by falling off the end of your code,
+even if that's not what you want.
+
+As an example of this case, this code prints the message
+"Perl exited with active threads: 2 running and unjoined":
+
+ use threads;
+ my $thr1 = threads->new(\&thrsub, "test1");
+ my $thr2 = threads->new(\&thrsub, "test2");
+ sub thrsub {
+ my ($message) = @_;
+ sleep 1;
+ print "thread $message\n";
+ }
+
+But when the following lines are added at the end:
+
+ $thr1->join;
+ $thr2->join;
+
+it prints two lines of output, a perhaps more useful outcome.
+
=head1 Threads And Data
Now that we've covered the basics of threads, it's time for our next