| 1 | package Thread::Queue;
|
|---|
| 2 | use Thread qw(cond_wait cond_broadcast);
|
|---|
| 3 |
|
|---|
| 4 | use vars qw($VERSION);
|
|---|
| 5 | $VERSION = '1.00';
|
|---|
| 6 |
|
|---|
| 7 | =head1 NAME
|
|---|
| 8 |
|
|---|
| 9 | Thread::Queue - thread-safe queues (5.005-threads)
|
|---|
| 10 |
|
|---|
| 11 | =head1 CAVEAT
|
|---|
| 12 |
|
|---|
| 13 | This Perl installation is using the old unsupported "5.005 threads".
|
|---|
| 14 | Use of the old threads model is discouraged.
|
|---|
| 15 |
|
|---|
| 16 | For the whole story about the development of threads in Perl, and why
|
|---|
| 17 | you should B<not> be using "old threads" unless you know what you're
|
|---|
| 18 | doing, see the CAVEAT of the C<Thread> module.
|
|---|
| 19 |
|
|---|
| 20 | =head1 SYNOPSIS
|
|---|
| 21 |
|
|---|
| 22 | use Thread::Queue;
|
|---|
| 23 | my $q = new Thread::Queue;
|
|---|
| 24 | $q->enqueue("foo", "bar");
|
|---|
| 25 | my $foo = $q->dequeue; # The "bar" is still in the queue.
|
|---|
| 26 | my $foo = $q->dequeue_nb; # returns "bar", or undef if the queue was
|
|---|
| 27 | # empty
|
|---|
| 28 | my $left = $q->pending; # returns the number of items still in the queue
|
|---|
| 29 |
|
|---|
| 30 | =head1 DESCRIPTION
|
|---|
| 31 |
|
|---|
| 32 | A queue, as implemented by C<Thread::Queue> is a thread-safe data structure
|
|---|
| 33 | much like a list. Any number of threads can safely add elements to the end
|
|---|
| 34 | of the list, or remove elements from the head of the list. (Queues don't
|
|---|
|
|---|