Skip to content

Commit

Permalink
Merge pull request #3 from Dual-Life/develop
Browse files Browse the repository at this point in the history
Document that detached threads suppress the global destruction phase
  • Loading branch information
jdhedden committed May 21, 2016
2 parents 957ca35 + 5f09b25 commit a4c1bee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Revision history for Perl extension threads.
-
-

2.09 Fri May 20 18:58:20 2016
- Document that detached threads suppress the global destruction phase

2.08 Mon May 16 17:40:57 2016
- Make t/test.pl compatible with Perls < 5.10 (again)

Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
threads version 2.08
threads version 2.09
====================

This module exposes interpreter threads to the Perl level.
Expand Down
16 changes: 14 additions & 2 deletions lib/threads.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use 5.008;
use strict;
use warnings;

our $VERSION = '2.08';
our $VERSION = '2.09';
my $XS_VERSION = $VERSION;
$VERSION = eval $VERSION;

Expand Down Expand Up @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads
=head1 VERSION
This document describes threads version 2.08
This document describes threads version 2.09
=head1 WARNING
Expand Down Expand Up @@ -1061,6 +1061,18 @@ In prior perl versions, spawning threads with open directory handles would
crash the interpreter.
L<[perl #75154]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=75154>
=item Detached threads and global destruction
If the main thread exits while there are detached threads which are still
running, then Perl's global destruction phase is not executed because
otherwise certain global structures that control the operation of threads and
that are allocated in the main thread's memory may get destroyed before the
detached thread is destroyed.
If you are using any code that requires the execution of the global
destruction phase for clean up (e.g., removing temp files), then do not use
detached threads, but rather join all threads before exiting the program.
=item Perl Bugs and the CPAN Version of L<threads>
Support for threads extends beyond the code in this module (i.e.,
Expand Down
10 changes: 5 additions & 5 deletions t/exit.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ my $rc = $thr->join();
ok(! defined($rc), 'Exited: threads->exit()');


run_perl(prog => 'use threads 2.08;' .
run_perl(prog => 'use threads 2.09;' .
'threads->exit(86);' .
'exit(99);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand Down Expand Up @@ -98,7 +98,7 @@ $rc = $thr->join();
ok(! defined($rc), 'Exited: $thr->set_thread_exit_only');


run_perl(prog => 'use threads 2.08 qw(exit thread_only);' .
run_perl(prog => 'use threads 2.09 qw(exit thread_only);' .
'threads->create(sub { exit(99); })->join();' .
'exit(86);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand All @@ -108,7 +108,7 @@ run_perl(prog => 'use threads 2.08 qw(exit thread_only);' .
is($?>>8, 86, "'use threads 'exit' => 'thread_only'");
}

my $out = run_perl(prog => 'use threads 2.08;' .
my $out = run_perl(prog => 'use threads 2.09;' .
'threads->create(sub {' .
' exit(99);' .
'});' .
Expand All @@ -124,7 +124,7 @@ my $out = run_perl(prog => 'use threads 2.08;' .
like($out, qr/1 finished and unjoined/, "exit(status) in thread");


$out = run_perl(prog => 'use threads 2.08 qw(exit thread_only);' .
$out = run_perl(prog => 'use threads 2.09 qw(exit thread_only);' .
'threads->create(sub {' .
' threads->set_thread_exit_only(0);' .
' exit(99);' .
Expand All @@ -141,7 +141,7 @@ $out = run_perl(prog => 'use threads 2.08 qw(exit thread_only);' .
like($out, qr/1 finished and unjoined/, "set_thread_exit_only(0)");


run_perl(prog => 'use threads 2.08;' .
run_perl(prog => 'use threads 2.09;' .
'threads->create(sub {' .
' $SIG{__WARN__} = sub { exit(99); };' .
' die();' .
Expand Down
2 changes: 1 addition & 1 deletion t/thread.t
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ package main;

# bugid #24165

run_perl(prog => 'use threads 2.08;' .
run_perl(prog => 'use threads 2.09;' .
'sub a{threads->create(shift)} $t = a sub{};' .
'$t->tid; $t->join; $t->tid',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
Expand Down

0 comments on commit a4c1bee

Please sign in to comment.