Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/barrier.html @ 25

Last change on this file since 25 was 12, checked in by landauf, 17 years ago

added boost

File size: 7.3 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Class barrier</title>
5<link rel="stylesheet" href="boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="index.html" title="The Boost C++ Libraries">
8<link rel="up" href="threads/reference.html#id2616214" title="Header &lt;boost/thread/barrier.hpp&gt;">
9<link rel="prev" href="threads/reference.html" title="Reference">
10<link rel="next" href="condition.html" title="Class condition">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
15<td align="center"><a href="../../index.htm">Home</a></td>
16<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../people/people.htm">People</a></td>
18<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="threads/reference.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="threads/reference.html#id2616214"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="condition.html"><img src="images/next.png" alt="Next"></a>
24</div>
25<div class="refentry" lang="en">
26<a name="barrier"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Class barrier</span></h2>
29<p>boost::barrier &#8212; <p>An object of class <a href="barrier.html" title="Class barrier">barrier</a> is a synchronization
30        primitive used  to cause a set of threads to wait until they each perform a
31        certain function or each reach a particular point in their execution.</p></p>
32</div>
33<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
34<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis">
35<span class="bold"><strong>class</strong></span> barrier : <span class="bold"><strong>private</strong></span> boost::noncopyable   <span class="emphasis"><em>// Exposition only</em></span>
36{
37<span class="bold"><strong>public</strong></span>:
38  <span class="emphasis"><em>// <a href="barrier.html#barrierconstruct-copy-destruct">construct/copy/destruct</a></em></span>
39  <a href="barrier.html#id2605020-bb">barrier</a>(size_t);
40  <a href="barrier.html#id2535874-bb">~barrier</a>();
41
42  <span class="emphasis"><em>// <a href="barrier.html#id2435312-bb">waiting</a></em></span>
43  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="barrier.html#id2620360-bb">wait</a>();
44};</pre></div>
45<div class="refsect1" lang="en">
46<a name="id2778820"></a><h2>Description</h2>
47<p>When a barrier is created, it is initialized with a thread count N.
48                The first N-1 calls to <code class="computeroutput">wait()</code> will all cause their threads to be blocked.
49                The Nth call to <code class="computeroutput">wait()</code> will allow all  of the waiting threads, including
50                the Nth thread, to be placed in a ready state.  The Nth call will also "reset"
51                the barrier such that, if an additional N+1th call is made to <code class="computeroutput">wait()</code>,
52                it will be as though this were the first call to <code class="computeroutput">wait()</code>; in other
53                words, the N+1th to 2N-1th calls to <code class="computeroutput">wait()</code> will cause their
54                threads to be blocked, and the 2Nth call to <code class="computeroutput">wait()</code> will allow all of
55                the waiting threads, including the 2Nth thread, to be placed in a ready state
56                and reset the barrier. This functionality allows the same set of N threads to re-use
57                a barrier object to  synchronize their execution at multiple points during their
58                execution.</p>
59<p>See <a href="threads.html#threads.glossary" title="Glossary">Glossary</a> for definitions of thread
60                states <a href="threads.html#threads.glossary.thread-state">blocked</a>
61                and <a href="threads.html#threads.glossary.thread-state">ready</a>.
62                Note that "waiting" is a synonym for blocked.</p>
63<div class="refsect2" lang="en">
64<a name="id2778899"></a><h3>
65<a name="barrierconstruct-copy-destruct"></a><code class="computeroutput">barrier</code> construct/copy/destruct</h3>
66<div class="orderedlist"><ol type="1">
67<li>
68<pre class="literallayout"><a name="id2605020-bb"></a>barrier(size_t count);</pre>
69<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
70
71    Constructs a <a href="barrier.html" title="Class barrier">barrier</a> object that
72        will cause <code class="computeroutput">count</code> threads to block on a call to <code class="computeroutput">wait()</code>.
73        </p>
74</li>
75<li>
76<pre class="literallayout"><a name="id2535874-bb"></a>~barrier();</pre>
77<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
78
79    Destroys <code class="computeroutput">*this</code>. If threads are still executing
80                their <code class="computeroutput">wait()</code> operations, the behavior for these threads is undefined.
81                </p>
82</li>
83</ol></div>
84</div>
85<div class="refsect2" lang="en">
86<a name="id2779000"></a><h3>
87<a name="id2435312-bb"></a><code class="computeroutput">barrier</code> waiting</h3>
88<div class="orderedlist"><ol type="1"><li>
89<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2620360-bb"></a>wait();</pre>
90<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
91
92    Wait until N threads call <code class="computeroutput">wait()</code>, where
93          N equals the <code class="computeroutput">count</code> provided to the constructor for the
94          barrier object.<p><span class="bold"><strong>Note</strong></span> that if the barrier is
95          destroyed before <code class="computeroutput">wait()</code> can return, the behavior is
96          undefined.</p><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
97
98    Exactly one of the N threads will receive a return value
99                  of <code class="computeroutput">true</code>, the others will receive a value of <code class="computeroutput">false</code>.
100                  Precisely which thread receives the return value of <code class="computeroutput">true</code> will
101                  be implementation-defined. Applications can use this value to designate one
102                  thread as a leader that will take a certain action, and the other threads
103                  emerging from the barrier can wait for that action to take place.</p>
104</li></ol></div>
105</div>
106</div>
107</div>
108<table width="100%"><tr>
109<td align="left"></td>
110<td align="right"><small>Copyright © 2001-2003 William E. Kempf</small></td>
111</tr></table>
112<hr>
113<div class="spirit-nav">
114<a accesskey="p" href="threads/reference.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="threads/reference.html#id2616214"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="condition.html"><img src="images/next.png" alt="Next"></a>
115</div>
116</body>
117</html>
Note: See TracBrowser for help on using the repository browser.