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.68.1"> |
---|
7 | <link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> |
---|
8 | <link rel="up" href="../thread/reference.html#header.boost.thread.barrier.hpp" title="Header <boost/thread/barrier.hpp>"> |
---|
9 | <link rel="prev" href="../thread/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 C++ Libraries" 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="../thread/reference.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread/reference.html#header.boost.thread.barrier.hpp"><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="boost.barrier"></a><div class="titlepage"></div> |
---|
27 | <div class="refnamediv"> |
---|
28 | <h2><span class="refentrytitle">Class barrier</span></h2> |
---|
29 | <p>boost::barrier — <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#boost.barrierconstruct-copy-destruct">construct/copy/destruct</a></em></span> |
---|
39 | <a href="barrier.html#id751828-bb">barrier</a>(size_t); |
---|
40 | <a href="barrier.html#id825827-bb">~barrier</a>(); |
---|
41 | |
---|
42 | <span class="emphasis"><em>// <a href="barrier.html#id768369-bb">waiting</a></em></span> |
---|
43 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="barrier.html#id768373-bb">wait</a>(); |
---|
44 | };</pre></div> |
---|
45 | <div class="refsect1" lang="en"> |
---|
46 | <a name="id1736550"></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="../thread.html#thread.glossary" title="Glossary">Glossary</a> for definitions of thread |
---|
60 | states <a href="../thread.html#thread.glossary.thread-state">blocked</a> |
---|
61 | and <a href="../thread.html#thread.glossary.thread-state">ready</a>. |
---|
62 | Note that "waiting" is a synonym for blocked.</p> |
---|
63 | <div class="refsect2" lang="en"> |
---|
64 | <a name="id1736632"></a><h3> |
---|
65 | <a name="boost.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="id751828-bb"></a>barrier(size_t count);</pre> |
---|
69 | <div class="variablelist"><table border="0"> |
---|
70 | <col align="left" valign="top"> |
---|
71 | <tbody><tr> |
---|
72 | <td> |
---|
73 | <span class="term">Effects:</span></td> |
---|
74 | <td>Constructs a <a href="barrier.html" title="Class barrier">barrier</a> object that |
---|
75 | will cause <code class="computeroutput">count</code> threads to block on a call to <code class="computeroutput">wait()</code>. |
---|
76 | </td> |
---|
77 | </tr></tbody> |
---|
78 | </table></div> |
---|
79 | </li> |
---|
80 | <li> |
---|
81 | <pre class="literallayout"><a name="id825827-bb"></a>~barrier();</pre> |
---|
82 | <div class="variablelist"><table border="0"> |
---|
83 | <col align="left" valign="top"> |
---|
84 | <tbody><tr> |
---|
85 | <td> |
---|
86 | <span class="term">Effects:</span></td> |
---|
87 | <td>Destroys <code class="computeroutput">*this</code>. If threads are still executing |
---|
88 | their <code class="computeroutput">wait()</code> operations, the behavior for these threads is undefined. |
---|
89 | </td> |
---|
90 | </tr></tbody> |
---|
91 | </table></div> |
---|
92 | </li> |
---|
93 | </ol></div> |
---|
94 | </div> |
---|
95 | <div class="refsect2" lang="en"> |
---|
96 | <a name="id1736735"></a><h3> |
---|
97 | <a name="id768369-bb"></a><code class="computeroutput">barrier</code> waiting</h3> |
---|
98 | <div class="orderedlist"><ol type="1"><li> |
---|
99 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id768373-bb"></a>wait();</pre> |
---|
100 | <div class="variablelist"><table border="0"> |
---|
101 | <col align="left" valign="top"> |
---|
102 | <tbody> |
---|
103 | <tr> |
---|
104 | <td> |
---|
105 | <span class="term">Effects:</span></td> |
---|
106 | <td> |
---|
107 | <p>Wait until N threads call <code class="computeroutput">wait()</code>, where |
---|
108 | N equals the <code class="computeroutput">count</code> provided to the constructor for the |
---|
109 | barrier object.</p> |
---|
110 | <p><span class="bold"><strong>Note</strong></span> that if the barrier is |
---|
111 | destroyed before <code class="computeroutput">wait()</code> can return, the behavior is |
---|
112 | undefined.</p> |
---|
113 | </td> |
---|
114 | </tr> |
---|
115 | <tr> |
---|
116 | <td> |
---|
117 | <span class="term">Returns:</span></td> |
---|
118 | <td>Exactly one of the N threads will receive a return value |
---|
119 | of <code class="computeroutput">true</code>, the others will receive a value of <code class="computeroutput">false</code>. |
---|
120 | Precisely which thread receives the return value of <code class="computeroutput">true</code> will |
---|
121 | be implementation-defined. Applications can use this value to designate one |
---|
122 | thread as a leader that will take a certain action, and the other threads |
---|
123 | emerging from the barrier can wait for that action to take place.</td> |
---|
124 | </tr> |
---|
125 | </tbody> |
---|
126 | </table></div> |
---|
127 | </li></ol></div> |
---|
128 | </div> |
---|
129 | </div> |
---|
130 | </div> |
---|
131 | <table width="100%"><tr> |
---|
132 | <td align="left"></td> |
---|
133 | <td align="right"><small>Copyright © 2001-2003 William E. Kempf</small></td> |
---|
134 | </tr></table> |
---|
135 | <hr> |
---|
136 | <div class="spirit-nav"> |
---|
137 | <a accesskey="p" href="../thread/reference.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread/reference.html#header.boost.thread.barrier.hpp"><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> |
---|
138 | </div> |
---|
139 | </body> |
---|
140 | </html> |
---|