New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
documentation enhancement to perlthrtut #9140
Comments
From johnh@isi.eduCreated by johnh@isi.eduA naive user (or at least, I) might assume that perl does an implicit It does not. This fact is not clear in the documentation, The attached patch to perlthrtut documents this behavior and shows -John Heidemann ---------------------------------------------------------------------- Inline Patch--- /tmp/perlthrtut.pod- 2007-12-05 09:24:45.000000000 -0800
+++ /tmp/perlthrtut.pod 2007-12-05 09:43:40.000000000 -0800
@@ -311,6 +311,36 @@
that it might have produced (if it was done and waiting for a join) is
lost.
+=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 error message
+"A thread exited while 3 threads were running":
+
+ 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.
+
---------------------------------------------------------------------- Perl Info
|
From @rgsOn 05/12/2007, via RT johnh @ isi. edu <perlbug-followup@perl.org> wrote:
Thanks, applied to the development version of perl. |
The RT System itself - Status changed from 'new' to 'open' |
@rgs - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#48214 (status was 'resolved')
Searchable as RT48214$
The text was updated successfully, but these errors were encountered: