56
56
<li><a href="http://search.cpan.org">CPAN</a></li>
57
<li><a href="http://www.perl.org">Perl.org</a></li>
57
58
<li><a href="http://www.perl.com">Perl.com</a></li>
58
<li><a href="http://www.perl.org">Perl.org</a></li>
59
<li><a href="http://perlbuzz.com">Perl Buzz</a></li>
60
<li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
61
<li><a href="http://jobs.perl.org">Perl Jobs</a></li>
59
62
<li><a href="http://www.pm.org">Perl Mongers</a></li>
60
63
<li><a href="http://www.perlmonks.org">Perl Monks</a></li>
61
64
<li><a href="http://planet.perl.org">Planet Perl</a></li>
66
69
<li>Site maintained by<br><a href="http://perl.jonallen.info">Jon Allen</a>
67
70
(<a href="http://perl.jonallen.info">JJ</a>)</li>
68
<li class="spaced">Last updated on<br>23 April 2006</li>
71
<li class="spaced">Last updated on<br>23 December 2007</li>
69
72
<li class="spaced">See the <a href="http://perl.jonallen.info/projects/perldoc">project page</a> for
76
79
<div id="centerContent">
77
80
<div id="contentHeader">
78
81
<div id="contentHeaderLeft"><a href="#" onClick="showLeft()">Show navigation</a></div>
79
<div id="contentHeaderCentre">-- Perl 5.8.8 documentation --</div>
82
<div id="contentHeaderCentre">-- Perl 5.10.0 documentation --</div>
80
83
<div id="contentHeaderRight"><a href="#" onClick="showRight()">Show toolbar</a></div>
82
85
<div id="breadCrumbs"><a href="../index.html">Home</a> > <a href="../index-modules-A.html">Core modules</a> > <a href="../index-modules-T.html">T</a> > Thread::Queue</div>
84
87
<div id="contentBody"><div class="title_container"><div class="page_title">Thread::Queue</div></div><ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#FUNCTIONS-AND-METHODS">FUNCTIONS AND METHODS</a><li><a href="#SEE-ALSO">SEE ALSO</a></ul><a name="NAME"></a><h1>NAME</h1>
85
88
<p>Thread::Queue - thread-safe queues</p>
86
89
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
87
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <a class="l_w" href="../Thread/Queue.html">Thread::Queue</a><span class="sc">;</span>
88
<a class="l_k" href="../functions/my.html">my</a> <span class="i">$q</span> = new <a class="l_w" href="../Thread/Queue.html">Thread::Queue</a><span class="sc">;</span>
90
<pre class="verbatim"> <a class="l_k" href="../functions/use.html">use</a> <span class="w">Thread::Queue</span><span class="sc">;</span>
91
<a class="l_k" href="../functions/my.html">my</a> <span class="i">$q</span> = <span class="w">new</span> <span class="w">Thread::Queue</span><span class="sc">;</span>
89
92
<span class="i">$q</span><span class="i">->enqueue</span><span class="s">(</span><span class="q">"foo"</span><span class="cm">,</span> <span class="q">"bar"</span><span class="s">)</span><span class="sc">;</span>
90
93
<a class="l_k" href="../functions/my.html">my</a> <span class="i">$foo</span> = <span class="i">$q</span><span class="i">->dequeue</span><span class="sc">;</span> <span class="c"># The "bar" is still in the queue.</span>
91
94
<a class="l_k" href="../functions/my.html">my</a> <span class="i">$foo</span> = <span class="i">$q</span><span class="i">->dequeue_nb</span><span class="sc">;</span> <span class="c"># returns "bar", or undef if the queue was empty</span>
92
95
<a class="l_k" href="../functions/my.html">my</a> <span class="i">$left</span> = <span class="i">$q</span><span class="i">->pending</span><span class="sc">;</span> <span class="c"># returns the number of items still in the queue</span></pre>
93
96
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
94
<p>A queue, as implemented by <code class="inline"><a class="l_w" href="../Thread/Queue.html">Thread::Queue</a></code> is a thread-safe
97
<p>A queue, as implemented by <code class="inline"><span class="w">Thread::Queue</span></code>
95
99
data structure much like a list. Any number of threads can safely
96
100
add elements to the end of the list, or remove elements from the head
97
101
of the list. (Queues don't permit adding or removing elements from
99
103
<a name="FUNCTIONS-AND-METHODS"></a><h1>FUNCTIONS AND METHODS</h1>
101
105
<li><a name="new"></a><b>new</b>
102
<p>The <code class="inline">new</code>
106
<p>The <code class="inline"><span class="w">new</span></code>
103
107
function creates a new empty queue.</p>
105
109
<li><a name="enqueue-LIST"></a><b>enqueue LIST</b>
106
<p>The <code class="inline">enqueue</code>
110
<p>The <code class="inline"><span class="w">enqueue</span></code>
107
111
method adds a list of scalars on to the end of the queue.
108
112
The queue will grow as needed to accommodate the list.</p>
110
114
<li><a name="dequeue"></a><b>dequeue</b>
111
<p>The <code class="inline">dequeue</code>
115
<p>The <code class="inline"><span class="w">dequeue</span></code>
112
116
method removes a scalar from the head of the queue and
113
returns it. If the queue is currently empty, <code class="inline">dequeue</code>
117
returns it. If the queue is currently empty, <code class="inline"><span class="w">dequeue</span></code>
115
thread until another thread <code class="inline">enqueue</code>
119
thread until another thread <code class="inline"><span class="w">enqueue</span></code>
118
122
<li><a name="dequeue_nb"></a><b>dequeue_nb</b>
119
<p>The <code class="inline">dequeue_nb</code>
120
method, like the <code class="inline">dequeue</code>
123
<p>The <code class="inline"><span class="w">dequeue_nb</span></code>
124
method, like the <code class="inline"><span class="w">dequeue</span></code>
121
125
method, removes a scalar from
122
the head of the queue and returns it. Unlike <code class="inline">dequeue</code>
126
the head of the queue and returns it. Unlike <code class="inline"><span class="w">dequeue</span></code>
124
<code class="inline">dequeue_nb</code>
128
<code class="inline"><span class="w">dequeue_nb</span></code>
125
129
won't block if the queue is empty, instead returning
126
130
<code class="inline"><a class="l_k" href="../functions/undef.html">undef</a></code>.</p>
128
132
<li><a name="pending"></a><b>pending</b>
129
<p>The <code class="inline">pending</code>
133
<p>The <code class="inline"><span class="w">pending</span></code>
130
134
method returns the number of items still in the queue.</p>