summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElizabeth Mattijsen <liz@dijkmat.nl>2002-06-08 01:57:01 +0200
committerJarkko Hietaniemi <jhi@iki.fi>2002-06-07 20:59:14 +0000
commit3d1f1caf68f964a756e1ffb5a4c6bc032cad2402 (patch)
tree2b7e864edc88fd60c371ca0087b9fdb28945d47c /lib
parent56d3e32d092cbfd472663b5f2168553262c8df58 (diff)
downloadperl-3d1f1caf68f964a756e1ffb5a4c6bc032cad2402.tar.gz
Re: [DOCPATCH] Thread.pm
Message-Id: <4.2.0.58.20020607235418.02e23680@mickey.dijkmat.nl> p4raw-id: //depot/perl@17072
Diffstat (limited to 'lib')
-rw-r--r--lib/Thread.pm4
-rw-r--r--lib/Thread/Queue.pm37
-rw-r--r--lib/Thread/Semaphore.pm34
3 files changed, 49 insertions, 26 deletions
diff --git a/lib/Thread.pm b/lib/Thread.pm
index fe277e81fe..c9f05c0526 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<Thread> module is discouraged and
-the direct use use of the C<threads> and C<threads::shared> modules
+the direct use of the C<threads> and C<threads::shared> 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 52854681cf..ebecb7433f 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<Thread::Queue> module is discouraged and
+the direct use of the C<threads>, C<threads::shared> and
+C<threads::shared::queue> modules is encouraged instead.
+
+For the whole story about the development of threads in Perl, and why you
+should B<not> be using this module unless you know what you're doing, see the
+CAVEAT of the C<Thread> 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 66e8878c8e..51cc0c6fef 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<Thread::Semaphore> module is discouraged and
+the direct use of the C<threads>, C<threads::shared> and
+C<threads::shared::semaphore> modules is encouraged instead.
+
+For the whole story about the development of threads in Perl, and why you
+should B<not> be using this module unless you know what you're doing, see the
+CAVEAT of the C<Thread> module.
=head1 SYNOPSIS