10 Thread::Queue - thread-safe queues
15 my $q = new Thread::Queue;
16 $q->enqueue("foo", "bar");
17 my $foo = $q->dequeue; # The "bar" is still in the queue.
18 my $foo = $q->dequeue_nb; # returns "bar", or undef if the queue was empty
19 my $left = $q->pending; # returns the number of items still in the queue
23 A queue, as implemented by C<Thread::Queue> is a thread-safe
24 data structure much like a list. Any number of threads can safely
25 add elements to the end of the list, or remove elements from the head
26 of the list. (Queues don't permit adding or removing elements from
27 the middle of the list).
29 =head1 FUNCTIONS AND METHODS
35 The C<new> function creates a new empty queue.
39 The C<enqueue> method adds a list of scalars on to the end of the queue.
40 The queue will grow as needed to accommodate the list.
44 The C<dequeue> method removes a scalar from the head of the queue and
45 returns it. If the queue is currently empty, C<dequeue> will block the
46 thread until another thread C<enqueue>s a scalar.
50 The C<dequeue_nb> method, like the C<dequeue> method, removes a scalar from
51 the head of the queue and returns it. Unlike C<dequeue>, though,
52 C<dequeue_nb> won't block if the queue is empty, instead returning
57 The C<pending> method returns the number of items still in the queue.
63 L<threads>, L<threads::shared>
70 return bless \@q, $class;
76 cond_wait @$q until @$q;
77 cond_signal @$q if @$q > 1;
90 push @$q, @_ and cond_signal @$q;