From: Elizabeth Mattijsen Date: Fri, 7 Jun 2002 23:57:01 +0000 (+0200) Subject: Re: [DOCPATCH] Thread.pm X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3d1f1caf68f964a756e1ffb5a4c6bc032cad2402;p=p5sagit%2Fp5-mst-13.2.git Re: [DOCPATCH] Thread.pm Message-Id: <4.2.0.58.20020607235418.02e23680@mickey.dijkmat.nl> p4raw-id: //depot/perl@17072 --- diff --git a/lib/Thread.pm b/lib/Thread.pm index fe277e8..c9f05c0 100644 --- a/lib/Thread.pm +++ b/lib/Thread.pm @@ -28,7 +28,7 @@ BEGIN { =head1 NAME -Thread - manipulate threads in Perl +Thread - manipulate threads in Perl (for old code only) =head1 CAVEAT @@ -65,7 +65,7 @@ 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 use of the C and C modules +the direct use of the C and C modules is encouraged instead. Finally, note that there are many known serious problems with the diff --git a/lib/Thread/Queue.pm b/lib/Thread/Queue.pm index 5285468..ebecb74 100644 --- a/lib/Thread/Queue.pm +++ b/lib/Thread/Queue.pm @@ -1,34 +1,44 @@ package Thread::Queue; -our $VERSION = '1.00'; +use strict; -our $ithreads; -our $othreads; +our $VERSION = '1.00'; use Thread qw(cond_wait cond_broadcast); BEGIN { use Config; - $ithreads = $Config{useithreads}; - $othreads = $Config{use5005threads}; - if($ithreads) { + if ($Config{useithreads}) { require 'threads/shared/queue.pm'; - for my $m (qw(new enqueue dequeue dequeue_nb pending)) { + for my $meth (qw(new enqueue dequeue dequeue_nb pending)) { no strict 'refs'; - *{"Thread::Queue::$m"} = \&{"threads::shared::queue::${m}"}; + *{"Thread::Queue::$meth"} = \&{"threads::shared::queue::$meth"}; } - } else { - for my $m (qw(new enqueue dequeue dequeue_nb pending)) { + } elsif ($Config{use5005threads}) { + for my $meth (qw(new enqueue dequeue dequeue_nb pending)) { no strict 'refs'; - *{"Thread::Queue::$m"} = \&{"Thread::Queue::${m}_othread"}; + *{"Thread::Queue::$meth"} = \&{"Thread::Queue::${meth}_othread"}; } + } else { + require Carp; + Carp::croak("This Perl has neither ithreads nor 5005threads"); } } =head1 NAME -Thread::Queue - thread-safe queues +Thread::Queue - thread-safe queues (for old code only) + +=head1 CAVEAT + +For new code the use of the C module is discouraged and +the direct use of the C, C and +C modules is encouraged instead. + +For the whole story about the development of threads in Perl, and why you +should B be using this module unless you know what you're doing, see the +CAVEAT of the C module. =head1 SYNOPSIS @@ -113,8 +123,7 @@ sub enqueue_othread : locked : method { } sub pending_othread : locked : method { - my $q = shift; - return scalar(@$q); + return scalar(@{(shift)}); } 1; diff --git a/lib/Thread/Semaphore.pm b/lib/Thread/Semaphore.pm index 66e8878..51cc0c6 100644 --- a/lib/Thread/Semaphore.pm +++ b/lib/Thread/Semaphore.pm @@ -1,30 +1,44 @@ package Thread::Semaphore; -use Thread qw(cond_wait cond_broadcast); + +use strict; our $VERSION = '1.00'; +use Thread qw(cond_wait cond_broadcast); + BEGIN { use Config; - $ithreads = $Config{useithreads}; - $othreads = $Config{use5005threads}; - if($ithreads) { + if ($Config{useithreads}) { require 'threads/shared/semaphore.pm'; - for my $m (qw(new up down)) { + for my $meth (qw(new up down)) { no strict 'refs'; - *{"Thread::Semaphore::$m"} = \&{"threads::shared::semaphore::${m}"}; + *{"Thread::Semaphore::$meth"} = \&{"threads::shared::semaphore::$meth"}; } - } else { - for my $m (qw(new up down)) { + } elsif ($Config{use5005threads}) { + for my $meth (qw(new up down)) { no strict 'refs'; - *{"Thread::Semaphore::$m"} = \&{"Thread::Semaphore::${m}_othread"}; + *{"Thread::Semaphore::$meth"} = \&{"Thread::Semaphore::${meth}_othread"}; } + } else { + require Carp; + Carp::croak("This Perl has neither ithreads nor 5005threads"); } } =head1 NAME -Thread::Semaphore - thread-safe semaphores +Thread::Semaphore - thread-safe semaphores (for old code only) + +=head1 CAVEAT + +For new code the use of the C module is discouraged and +the direct use of the C, C and +C modules is encouraged instead. + +For the whole story about the development of threads in Perl, and why you +should B be using this module unless you know what you're doing, see the +CAVEAT of the C module. =head1 SYNOPSIS