1 | <?xml version="1.0" encoding="utf-8"?> |
---|
2 | <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" |
---|
3 | "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd" [ |
---|
4 | <!ENTITY % threads.entities SYSTEM "entities.xml"> |
---|
5 | %threads.entities; |
---|
6 | ]> |
---|
7 | <header name="boost/thread/barrier.hpp" |
---|
8 | last-revision="$Date: 2004/07/17 04:33:59 $"> |
---|
9 | <namespace name="boost"> |
---|
10 | <class name="barrier"> |
---|
11 | <inherit access="private"> |
---|
12 | <type><classname>boost::noncopyable</classname></type> |
---|
13 | <purpose>Exposition only</purpose> |
---|
14 | </inherit> |
---|
15 | |
---|
16 | <purpose> |
---|
17 | <para>An object of class <classname>barrier</classname> is a synchronization |
---|
18 | primitive used to cause a set of threads to wait until they each perform a |
---|
19 | certain function or each reach a particular point in their execution.</para> |
---|
20 | </purpose> |
---|
21 | |
---|
22 | <description> |
---|
23 | <para>When a barrier is created, it is initialized with a thread count N. |
---|
24 | The first N-1 calls to <code>wait()</code> will all cause their threads to be blocked. |
---|
25 | The Nth call to <code>wait()</code> will allow all of the waiting threads, including |
---|
26 | the Nth thread, to be placed in a ready state. The Nth call will also "reset" |
---|
27 | the barrier such that, if an additional N+1th call is made to <code>wait()</code>, |
---|
28 | it will be as though this were the first call to <code>wait()</code>; in other |
---|
29 | words, the N+1th to 2N-1th calls to <code>wait()</code> will cause their |
---|
30 | threads to be blocked, and the 2Nth call to <code>wait()</code> will allow all of |
---|
31 | the waiting threads, including the 2Nth thread, to be placed in a ready state |
---|
32 | and reset the barrier. This functionality allows the same set of N threads to re-use |
---|
33 | a barrier object to synchronize their execution at multiple points during their |
---|
34 | execution.</para> |
---|
35 | <para>See <xref linkend="threads.glossary"/> for definitions of thread |
---|
36 | states <link linkend="threads.glossary.thread-state">blocked</link> |
---|
37 | and <link linkend="threads.glossary.thread-state">ready</link>. |
---|
38 | Note that "waiting" is a synonym for blocked.</para> |
---|
39 | </description> |
---|
40 | |
---|
41 | <constructor> |
---|
42 | <parameter name="count"> |
---|
43 | <paramtype>size_t</paramtype> |
---|
44 | </parameter> |
---|
45 | |
---|
46 | <effects><simpara>Constructs a <classname>barrier</classname> object that |
---|
47 | will cause <code>count</code> threads to block on a call to <code>wait()</code>. |
---|
48 | </simpara></effects> |
---|
49 | </constructor> |
---|
50 | |
---|
51 | <destructor> |
---|
52 | <effects><simpara>Destroys <code>*this</code>. If threads are still executing |
---|
53 | their <code>wait()</code> operations, the behavior for these threads is undefined. |
---|
54 | </simpara></effects> |
---|
55 | </destructor> |
---|
56 | |
---|
57 | <method-group name="waiting"> |
---|
58 | <method name="wait"> |
---|
59 | <type>bool</type> |
---|
60 | |
---|
61 | <effects><simpara>Wait until N threads call <code>wait()</code>, where |
---|
62 | N equals the <code>count</code> provided to the constructor for the |
---|
63 | barrier object.</simpara> |
---|
64 | <simpara><emphasis role="bold">Note</emphasis> that if the barrier is |
---|
65 | destroyed before <code>wait()</code> can return, the behavior is |
---|
66 | undefined.</simpara></effects> |
---|
67 | |
---|
68 | <returns>Exactly one of the N threads will receive a return value |
---|
69 | of <code>true</code>, the others will receive a value of <code>false</code>. |
---|
70 | Precisely which thread receives the return value of <code>true</code> will |
---|
71 | be implementation-defined. Applications can use this value to designate one |
---|
72 | thread as a leader that will take a certain action, and the other threads |
---|
73 | emerging from the barrier can wait for that action to take place.</returns> |
---|
74 | </method> |
---|
75 | </method-group> |
---|
76 | </class> |
---|
77 | </namespace> |
---|
78 | </header> |
---|