1Thread::Queue(3pm) Perl Programmers Reference Guide Thread::Queue(3pm)
2
3
4
6 Thread::Queue - thread-safe queues
7
9 use Thread::Queue;
10 my $q = new Thread::Queue;
11 $q->enqueue("foo", "bar");
12 my $foo = $q->dequeue; # The "bar" is still in the queue.
13 my $foo = $q->dequeue_nb; # returns "bar", or undef if the queue was empty
14 my $left = $q->pending; # returns the number of items still in the queue
15
17 A queue, as implemented by "Thread::Queue" is a thread-safe data strucā
18 ture much like a list. Any number of threads can safely add elements
19 to the end of the list, or remove elements from the head of the list.
20 (Queues don't permit adding or removing elements from the middle of the
21 list).
22
24 new The "new" function creates a new empty queue.
25
26 enqueue LIST
27 The "enqueue" method adds a list of scalars on to the end of
28 the queue. The queue will grow as needed to accommodate the
29 list.
30
31 dequeue The "dequeue" method removes a scalar from the head of the
32 queue and returns it. If the queue is currently empty,
33 "dequeue" will block the thread until another thread "enqueue"s
34 a scalar.
35
36 dequeue_nb
37 The "dequeue_nb" method, like the "dequeue" method, removes a
38 scalar from the head of the queue and returns it. Unlike
39 "dequeue", though, "dequeue_nb" won't block if the queue is
40 empty, instead returning "undef".
41
42 pending The "pending" method returns the number of items still in the
43 queue.
44
46 threads, threads::shared
47
48
49
50perl v5.8.8 2001-09-21 Thread::Queue(3pm)