queue.html

来自「perl教程」· HTML 代码 · 共 111 行

HTML
111
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Thread::Queue - thread-safe queues</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Thread::Queue - thread-safe queues</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#functions_and_methods">FUNCTIONS AND METHODS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Thread::Queue - thread-safe queues</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
    <span class="keyword">use</span> <span class="variable">Thread::Queue</span><span class="operator">;</span>
    <span class="keyword">my</span> <span class="variable">$q</span> <span class="operator">=</span> <span class="variable">new</span> <span class="variable">Thread::Queue</span><span class="operator">;</span>
    <span class="variable">$q</span><span class="operator">-&gt;</span><span class="variable">enqueue</span><span class="operator">(</span><span class="string">"foo"</span><span class="operator">,</span> <span class="string">"bar"</span><span class="operator">);</span>
    <span class="keyword">my</span> <span class="variable">$foo</span> <span class="operator">=</span> <span class="variable">$q</span><span class="operator">-&gt;</span><span class="variable">dequeue</span><span class="operator">;</span>    <span class="comment"># The "bar" is still in the queue.</span>
    <span class="keyword">my</span> <span class="variable">$foo</span> <span class="operator">=</span> <span class="variable">$q</span><span class="operator">-&gt;</span><span class="variable">dequeue_nb</span><span class="operator">;</span> <span class="comment"># returns "bar", or undef if the queue was empty</span>
    <span class="keyword">my</span> <span class="variable">$left</span> <span class="operator">=</span> <span class="variable">$q</span><span class="operator">-&gt;</span><span class="variable">pending</span><span class="operator">;</span>   <span class="comment"># returns the number of items still in the queue</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>A queue, as implemented by <code>Thread::Queue</code> is a thread-safe 
data structure much like a list.  Any number of threads can safely 
add elements to the end of the list, or remove elements from the head 
of the list. (Queues don't permit adding or removing elements from 
the middle of the list).</p>
<p>
</p>
<hr />
<h1><a name="functions_and_methods">FUNCTIONS AND METHODS</a></h1>
<dl>
<dt><strong><a name="item_new">new</a></strong>

<dd>
<p>The <a href="#item_new"><code>new</code></a> function creates a new empty queue.</p>
</dd>
</li>
<dt><strong><a name="item_enqueue">enqueue LIST</a></strong>

<dd>
<p>The <a href="#item_enqueue"><code>enqueue</code></a> method adds a list of scalars on to the end of the queue.
The queue will grow as needed to accommodate the list.</p>
</dd>
</li>
<dt><strong><a name="item_dequeue">dequeue</a></strong>

<dd>
<p>The <a href="#item_dequeue"><code>dequeue</code></a> method removes a scalar from the head of the queue and
returns it. If the queue is currently empty, <a href="#item_dequeue"><code>dequeue</code></a> will block the
thread until another thread <a href="#item_enqueue"><code>enqueue</code></a>s a scalar.</p>
</dd>
</li>
<dt><strong><a name="item_dequeue_nb">dequeue_nb</a></strong>

<dd>
<p>The <a href="#item_dequeue_nb"><code>dequeue_nb</code></a> method, like the <a href="#item_dequeue"><code>dequeue</code></a> method, removes a scalar from
the head of the queue and returns it. Unlike <a href="#item_dequeue"><code>dequeue</code></a>, though,
<a href="#item_dequeue_nb"><code>dequeue_nb</code></a> won't block if the queue is empty, instead returning
<a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a>.</p>
</dd>
</li>
<dt><strong><a name="item_pending">pending</a></strong>

<dd>
<p>The <a href="#item_pending"><code>pending</code></a> method returns the number of items still in the queue.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/threads.html">the threads manpage</a>, <a href="../../lib/threads/shared.html">the threads::shared manpage</a></p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?