summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry D. Hedden <jdhedden@cpan.org>2011-09-02 23:28:00 -0400
committerFather Chrysostomos <sprout@cpan.org>2011-09-02 21:52:47 -0700
commit794373aa167d0474c91729512a97fb536b5cb197 (patch)
tree4a4f0bd3c9d91117b38ce2a50de21d60739784dd
parentb9e224a704c414f79a5ecfa804e1a6fd448f192c (diff)
downloadperl-794373aa167d0474c91729512a97fb536b5cb197.tar.gz
Upgrade to threads 1.84
-rwxr-xr-xPorting/Maintainers.pl2
-rw-r--r--dist/threads/lib/threads.pm32
-rw-r--r--dist/threads/t/exit.t10
-rw-r--r--dist/threads/t/thread.t2
4 files changed, 38 insertions, 8 deletions
diff --git a/Porting/Maintainers.pl b/Porting/Maintainers.pl
index 0bee529367..b86451d37a 100755
--- a/Porting/Maintainers.pl
+++ b/Porting/Maintainers.pl
@@ -1878,7 +1878,7 @@ use File::Glob qw(:case);
'threads' =>
{
'MAINTAINER' => 'jdhedden',
- 'DISTRIBUTION' => 'JDHEDDEN/threads-1.83.tar.gz',
+ 'DISTRIBUTION' => 'JDHEDDEN/threads-1.84.tar.gz',
'FILES' => q[dist/threads],
'EXCLUDED' => [ qr{^examples/},
qw(t/pod.t
diff --git a/dist/threads/lib/threads.pm b/dist/threads/lib/threads.pm
index 29c9de02c0..ba35120246 100644
--- a/dist/threads/lib/threads.pm
+++ b/dist/threads/lib/threads.pm
@@ -134,7 +134,7 @@ threads - Perl interpreter-based threads
=head1 VERSION
-This document describes threads version 1.83
+This document describes threads version 1.84
=head1 SYNOPSIS
@@ -939,6 +939,36 @@ For example:
On MSWin32, each thread maintains its own set of environment variables.
+=item Catching signals
+
+Signals are I<caught> by the main thread (thread ID = 0) of a script.
+Therefore, setting up signal handlers in threads for purposes other than
+L</"THREAD SIGNALLING"> as documented above will not accomplish what is
+intended.
+
+This is especially true if trying to catch C<SIGALRM> in a thread. To handle
+alarms in threads, set up a signal handler in the main thread, and then use
+L</"THREAD SIGNALLING"> to relay the signal to the thread:
+
+ # Create thread with a task that may time out
+ my $thr->create(sub {
+ threads->yield();
+ eval {
+ $SIG{ALRM} = sub { die("Timeout\n"); };
+ alarm(10);
+ ... # Do work here
+ alarm(0);
+ };
+ if ($@ =~ /Timeout/) {
+ warn("Task in thread timed out\n");
+ }
+ };
+
+ # Set signal handler to relay SIGALRM to thread
+ $SIG{ALRM} = sub { $thr->kill('ALRM') };
+
+ ... # Main thread continues working
+
=item Parent-child threads
On some platforms, it might not be possible to destroy I<parent> threads while
diff --git a/dist/threads/t/exit.t b/dist/threads/t/exit.t
index a76788618a..d0c80a62d2 100644
--- a/dist/threads/t/exit.t
+++ b/dist/threads/t/exit.t
@@ -48,7 +48,7 @@ my $rc = $thr->join();
ok(! defined($rc), 'Exited: threads->exit()');
-run_perl(prog => 'use threads 1.83;' .
+run_perl(prog => 'use threads 1.84;' .
'threads->exit(86);' .
'exit(99);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
@@ -98,7 +98,7 @@ $rc = $thr->join();
ok(! defined($rc), 'Exited: $thr->set_thread_exit_only');
-run_perl(prog => 'use threads 1.83 qw(exit thread_only);' .
+run_perl(prog => 'use threads 1.84 qw(exit thread_only);' .
'threads->create(sub { exit(99); })->join();' .
'exit(86);',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,
@@ -108,7 +108,7 @@ run_perl(prog => 'use threads 1.83 qw(exit thread_only);' .
is($?>>8, 86, "'use threads 'exit' => 'thread_only'");
}
-my $out = run_perl(prog => 'use threads 1.83;' .
+my $out = run_perl(prog => 'use threads 1.84;' .
'threads->create(sub {' .
' exit(99);' .
'});' .
@@ -124,7 +124,7 @@ my $out = run_perl(prog => 'use threads 1.83;' .
like($out, '1 finished and unjoined', "exit(status) in thread");
-$out = run_perl(prog => 'use threads 1.83 qw(exit thread_only);' .
+$out = run_perl(prog => 'use threads 1.84 qw(exit thread_only);' .
'threads->create(sub {' .
' threads->set_thread_exit_only(0);' .
' exit(99);' .
@@ -141,7 +141,7 @@ $out = run_perl(prog => 'use threads 1.83 qw(exit thread_only);' .
like($out, '1 finished and unjoined', "set_thread_exit_only(0)");
-run_perl(prog => 'use threads 1.83;' .
+run_perl(prog => 'use threads 1.84;' .
'threads->create(sub {' .
' $SIG{__WARN__} = sub { exit(99); };' .
' die();' .
diff --git a/dist/threads/t/thread.t b/dist/threads/t/thread.t
index 5ca3d1a656..f4d464578b 100644
--- a/dist/threads/t/thread.t
+++ b/dist/threads/t/thread.t
@@ -161,7 +161,7 @@ package main;
# bugid #24165
-run_perl(prog => 'use threads 1.83;' .
+run_perl(prog => 'use threads 1.84;' .
'sub a{threads->create(shift)} $t = a sub{};' .
'$t->tid; $t->join; $t->tid',
nolib => ($ENV{PERL_CORE}) ? 0 : 1,