X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FThread.pm;h=c9f05c0526c4cfd1a452da104c9b25269b5bab97;hb=46471bde41ad0777edf7b89818df6730e8b55c20;hp=c6489541bb011cd225714b62c86eb4f7ceb08907;hpb=d7ceb7fc1159206a67f149394fc7aa55f6b4f7dd;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Thread.pm b/lib/Thread.pm index c648954..c9f05c0 100644 --- a/lib/Thread.pm +++ b/lib/Thread.pm @@ -1,13 +1,11 @@ package Thread; -$VERSION = '2.00'; - use strict; -our $ithreads; -our $othreads; +our($VERSION, $ithreads, $othreads); BEGIN { + $VERSION = '2.00'; use Config; $ithreads = $Config{useithreads}; $othreads = $Config{use5005threads}; @@ -15,13 +13,13 @@ BEGIN { require Exporter; use XSLoader (); -our($VERSION, @ISA, @EXPORT, @EXPORT_OK); +our(@ISA, @EXPORT, @EXPORT_OK); @ISA = qw(Exporter); BEGIN { if ($ithreads) { - @EXPORT = qw(share cond_wait cond_broadcast cond_signal unlock) + @EXPORT = qw(cond_wait cond_broadcast cond_signal) } elsif ($othreads) { @EXPORT_OK = qw(cond_signal cond_broadcast cond_wait); } @@ -30,7 +28,7 @@ BEGIN { =head1 NAME -Thread - manipulate threads in Perl +Thread - manipulate threads in Perl (for old code only) =head1 CAVEAT @@ -52,15 +50,24 @@ In Perl 5.8 the ithreads model became available through the C module. Neither model is configured by default into Perl (except, as mentioned -above, in Win32 ithreads are always available.) +above, in Win32 ithreads are always available.) You can see your +Perl's threading configuration by running C and looking for +the I variables, or inside script by C +and testing for C<$Config{use5005threads}> and C<$Config{useithreads}>. + +For old code and interim backwards compatibility, the Thread module +has been reworked to function as a frontend for both 5005threads and +ithreads. -For backwards compatibility, the Thread module has been reworked -to function as a frontend for both 5005threads and ithreads. Note that the compatibility is not complete: because the data sharing models are directly opposed, anything to do with data sharing has to be thought differently. With the ithreads you must explicitly share() variables between the threads. +For new code the use of the C module is discouraged and +the direct use of the C and C modules +is encouraged instead. + Finally, note that there are many known serious problems with the 5005threads, one of the least of which is that regular expression match variables like $1 are not threadsafe, that is, they easily get @@ -100,8 +107,6 @@ use ithreads instead. my @list = Thread->list; # not available with ithreads - unlock(...); # not available with the 5.005 threads - use Thread 'async'; =head1 DESCRIPTION @@ -125,8 +130,7 @@ thread. =item lock VARIABLE -C places a lock on a variable until the lock goes out of scope -(with ithreads you can also explicitly unlock()). +C places a lock on a variable until the lock goes out of scope. If the variable is locked by another thread, the C call will block until it's available. C is recursive, so multiple calls @@ -306,24 +310,27 @@ sub unimplement { BEGIN { if ($ithreads) { + if ($othreads) { + require Carp; + Carp::croak("This Perl has both ithreads and 5005threads (serious malconfiguration)"); + } XSLoader::load 'threads'; - for my $m (qw(new join detach yield self tid equal)) { + for my $m (qw(new join detach yield self tid equal list)) { no strict 'refs'; *{"Thread::$m"} = \&{"threads::$m"}; } - XSLoader::load 'threads::shared'; - for my $m (qw(cond_signal cond_broadcast cond_wait unlock share)) { + require 'threads/shared.pm'; + for my $m (qw(cond_signal cond_broadcast cond_wait)) { no strict 'refs'; *{"Thread::$m"} = \&{"threads::shared::${m}_enabled"}; } # trying to unimplement eval gives redefined warning - unimplement(qw(list done flags)); + unimplement(qw(done flags)); } elsif ($othreads) { XSLoader::load 'Thread'; - unimplement(qw(unlock)); } else { require Carp; - Carp::croak("This Perl has neither ithreads not 5005threads"); + Carp::croak("This Perl has neither ithreads nor 5005threads"); } }