From: Jerry D. Hedden Date: Mon, 10 Aug 2009 19:08:29 +0000 (-0400) Subject: Upgrade to 'threads' 1.74 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3350824ec19fdd3cc42564918b8feb4f464bdcc0;p=p5sagit%2Fp5-mst-13.2.git Upgrade to 'threads' 1.74 Attached patch upgrade 'blead' to 'threads' 1.74: - Updated DESCRIPTION in POD - Added 'no_threads' test for non-threaded Perls The newly added test allows non-threaded Perls to install 'threads' with a 'PASS' instead of the ambiguous 'UNKNOWN'. Signed-off-by: H.Merijn Brand --- diff --git a/ext/threads/t/exit.t b/ext/threads/t/exit.t index 9e9ab10..7e42172 100644 --- a/ext/threads/t/exit.t +++ b/ext/threads/t/exit.t @@ -48,7 +48,7 @@ my $rc = $thr->join(); ok(! defined($rc), 'Exited: threads->exit()'); -run_perl(prog => 'use threads 1.73;' . +run_perl(prog => 'use threads 1.74;' . '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.73 qw(exit thread_only);' . +run_perl(prog => 'use threads 1.74 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.73 qw(exit thread_only);' . is($?>>8, 86, "'use threads 'exit' => 'thread_only'"); } -my $out = run_perl(prog => 'use threads 1.73;' . +my $out = run_perl(prog => 'use threads 1.74;' . 'threads->create(sub {' . ' exit(99);' . '});' . @@ -124,7 +124,7 @@ my $out = run_perl(prog => 'use threads 1.73;' . like($out, '1 finished and unjoined', "exit(status) in thread"); -$out = run_perl(prog => 'use threads 1.73 qw(exit thread_only);' . +$out = run_perl(prog => 'use threads 1.74 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.73 qw(exit thread_only);' . like($out, '1 finished and unjoined', "set_thread_exit_only(0)"); -run_perl(prog => 'use threads 1.73;' . +run_perl(prog => 'use threads 1.74;' . 'threads->create(sub {' . ' $SIG{__WARN__} = sub { exit(99); };' . ' die();' . diff --git a/ext/threads/t/no_threads.t b/ext/threads/t/no_threads.t new file mode 100644 index 0000000..1ed1e96 --- /dev/null +++ b/ext/threads/t/no_threads.t @@ -0,0 +1,39 @@ +use strict; +use warnings; + +BEGIN { + use Config; + if ($Config{'useithreads'}) { + print("1..0 # SKIP Perl compiled with 'useithreads'\n"); + exit(0); + } +} + +use ExtUtils::testlib; + +sub ok { + my ($id, $ok, $name) = @_; + + # You have to do it this way or VMS will get confused. + if ($ok) { + print("ok $id - $name\n"); + } else { + print("not ok $id - $name\n"); + printf("# Failed test at line %d\n", (caller)[2]); + } + + return ($ok); +} + +BEGIN { + $| = 1; + print("1..1\n"); ### Number of tests that will be run ### +}; + +eval 'use threads; 1'; + +ok(1, (($@ =~ /not built to support thread/)?1:0), "No threads support"); + +exit(0); + +# EOF diff --git a/ext/threads/t/thread.t b/ext/threads/t/thread.t index 531698d..a5df4f7 100644 --- a/ext/threads/t/thread.t +++ b/ext/threads/t/thread.t @@ -161,7 +161,7 @@ package main; # bugid #24165 -run_perl(prog => 'use threads 1.73;' . +run_perl(prog => 'use threads 1.74;' . 'sub a{threads->create(shift)} $t = a sub{};' . '$t->tid; $t->join; $t->tid', nolib => ($ENV{PERL_CORE}) ? 0 : 1, diff --git a/ext/threads/threads.pm b/ext/threads/threads.pm index a17dd77..8b9b2d8 100644 --- a/ext/threads/threads.pm +++ b/ext/threads/threads.pm @@ -5,7 +5,7 @@ use 5.008; use strict; use warnings; -our $VERSION = '1.73'; +our $VERSION = '1.74'; my $XS_VERSION = $VERSION; $VERSION = eval $VERSION; @@ -134,7 +134,7 @@ threads - Perl interpreter-based threads =head1 VERSION -This document describes threads version 1.73 +This document describes threads version 1.74 =head1 SYNOPSIS @@ -221,28 +221,38 @@ This document describes threads version 1.73 =head1 DESCRIPTION -Perl 5.6 introduced something called interpreter threads. Interpreter threads -are different from I<5005threads> (the thread model of Perl 5.005) by creating -a new Perl interpreter per thread, and not sharing any data or state between -threads by default. +Since Perl 5.8, thread programming has been available using a model called +I which provides a new Perl interpreter for each +thread, and, by default, results in no data or state information being shared +between threads. -Prior to Perl 5.8, this has only been available to people embedding Perl, and -for emulating fork() on Windows. +(Prior to Perl 5.8, I<5005threads> was available through the C API. +This threading model has been deprecated, and was removed as of Perl 5.10.0.) -The I API is loosely based on the old Thread.pm API. It is very -important to note that variables are not shared between threads, all variables -are by default thread local. To use shared variables one must also use -L: +As just mentioned, all variables are, by default, thread local. To use shared +variables, you need to also load L: use threads; use threads::shared; -It is also important to note that you must enable threads by doing C as early as possible in the script itself, and that it is not -possible to enable threading inside an C, C, C, or -C. In particular, if you are intending to share variables with -L, you must C before you C. -(C will emit a warning if you do it the other way around.) +When loading L, you must C before you +C. (C will emit a warning if you do it the +other way around.) + +It is strongly recommended that you enable threads via C as early +as possible in your script. + +If needed, scripts can be written so as to run on both threaded and +non-threaded Perls: + + my $can_use_threads = eval 'use threads; 1'; + if ($can_use_threads) { + # Do processing using threads + ... + } else { + # Do it without using threads + ... + } =over @@ -1011,7 +1021,7 @@ L Discussion Forum on CPAN: L Annotated POD for L: -L +L Source repository: L