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 % thread.entities SYSTEM "entities.xml"> |
---|
5 | %thread.entities; |
---|
6 | ]> |
---|
7 | <!-- Copyright (c) 2002-2003 William E. Kempf, Michael Glassford |
---|
8 | Subject to the Boost Software License, Version 1.0. |
---|
9 | (See accompanying file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0) |
---|
10 | --> |
---|
11 | <header name="boost/thread/thread.hpp" |
---|
12 | last-revision="$Date: 2006/10/15 14:52:54 $"> |
---|
13 | <namespace name="boost"> |
---|
14 | <class name="thread"> |
---|
15 | <purpose> |
---|
16 | <para>The <classname>thread</classname> class represents threads of |
---|
17 | execution, and provides the functionality to create and manage |
---|
18 | threads within the &Boost.Thread; library. See |
---|
19 | <xref linkend="thread.glossary"/> for a precise description of |
---|
20 | <link linkend="thread.glossary.thread">thread of execution</link>, |
---|
21 | and for definitions of threading-related terms and of thread states such as |
---|
22 | <link linkend="thread.glossary.thread-state">blocked</link>.</para> |
---|
23 | </purpose> |
---|
24 | |
---|
25 | <description> |
---|
26 | <para>A <link linkend="thread.glossary.thread">thread of execution</link> |
---|
27 | has an initial function. For the program's initial thread, the initial |
---|
28 | function is <code>main()</code>. For other threads, the initial |
---|
29 | function is <code>operator()</code> of the function object passed to |
---|
30 | the <classname>thread</classname> object's constructor.</para> |
---|
31 | |
---|
32 | <para>A thread of execution is said to be "finished" |
---|
33 | or to have "finished execution" when its initial function returns or |
---|
34 | is terminated. This includes completion of all thread cleanup |
---|
35 | handlers, and completion of the normal C++ function return behaviors, |
---|
36 | such as destruction of automatic storage (stack) objects and releasing |
---|
37 | any associated implementation resources.</para> |
---|
38 | |
---|
39 | <para>A thread object has an associated state which is either |
---|
40 | "joinable" or "non-joinable".</para> |
---|
41 | |
---|
42 | <para>Except as described below, the policy used by an implementation |
---|
43 | of &Boost.Thread; to schedule transitions between thread states is |
---|
44 | unspecified.</para> |
---|
45 | |
---|
46 | <para><note>Just as the lifetime of a file may be different from the |
---|
47 | lifetime of an <code>iostream</code> object which represents the file, the lifetime |
---|
48 | of a thread of execution may be different from the |
---|
49 | <classname>thread</classname> object which represents the thread of |
---|
50 | execution. In particular, after a call to <code>join()</code>, |
---|
51 | the thread of execution will no longer exist even though the |
---|
52 | <classname>thread</classname> object continues to exist until the |
---|
53 | end of its normal lifetime. The converse is also possible; if |
---|
54 | a <classname>thread</classname> object is destroyed without |
---|
55 | <code>join()</code> first having been called, the thread of execution |
---|
56 | continues until its initial function completes.</note></para> |
---|
57 | </description> |
---|
58 | |
---|
59 | <inherit access="private"> |
---|
60 | <type><classname>boost::noncopyable</classname></type> |
---|
61 | <purpose>Exposition only</purpose> |
---|
62 | </inherit> |
---|
63 | |
---|
64 | <constructor> |
---|
65 | <effects>Constructs a <classname>thread</classname> object |
---|
66 | representing the current thread of execution.</effects> |
---|
67 | |
---|
68 | <postconditions><code>*this</code> is non-joinable.</postconditions> |
---|
69 | |
---|
70 | <notes><emphasis role="bold">Danger:</emphasis> |
---|
71 | <code>*this</code> is valid only within the current thread.</notes> |
---|
72 | </constructor> |
---|
73 | |
---|
74 | <constructor specifiers="explicit"> |
---|
75 | <parameter name="threadfunc"> |
---|
76 | <paramtype>const boost::function0<void>&</paramtype> |
---|
77 | </parameter> |
---|
78 | |
---|
79 | <effects> |
---|
80 | Starts a new thread of execution and constructs a |
---|
81 | <classname>thread</classname> object representing it. |
---|
82 | Copies <code>threadfunc</code> (which in turn copies |
---|
83 | the function object wrapped by <code>threadfunc</code>) |
---|
84 | to an internal location which persists for the lifetime |
---|
85 | of the new thread of execution. Calls <code>operator()</code> |
---|
86 | on the copy of the <code>threadfunc</code> function object |
---|
87 | in the new thread of execution. |
---|
88 | </effects> |
---|
89 | |
---|
90 | <postconditions><code>*this</code> is joinable.</postconditions> |
---|
91 | |
---|
92 | <throws><code>boost::thread_resource_error</code> if a new thread |
---|
93 | of execution cannot be started.</throws> |
---|
94 | </constructor> |
---|
95 | |
---|
96 | <destructor> |
---|
97 | <effects>Destroys <code>*this</code>. The actual thread of |
---|
98 | execution may continue to execute after the |
---|
99 | <classname>thread</classname> object has been destroyed. |
---|
100 | </effects> |
---|
101 | |
---|
102 | <notes>If <code>*this</code> is joinable the actual thread |
---|
103 | of execution becomes "detached". Any resources used |
---|
104 | by the thread will be reclaimed when the thread of execution |
---|
105 | completes. To ensure such a thread of execution runs to completion |
---|
106 | before the <classname>thread</classname> object is destroyed, call |
---|
107 | <code>join()</code>.</notes> |
---|
108 | </destructor> |
---|
109 | |
---|
110 | <method-group name="comparison"> |
---|
111 | <method name="operator==" cv="const"> |
---|
112 | <type>bool</type> |
---|
113 | |
---|
114 | <parameter name="rhs"> |
---|
115 | <type>const thread&</type> |
---|
116 | </parameter> |
---|
117 | |
---|
118 | <requires>The thread is non-terminated or <code>*this</code> |
---|
119 | is joinable.</requires> |
---|
120 | |
---|
121 | <returns><code>true</code> if <code>*this</code> and |
---|
122 | <code>rhs</code> represent the same thread of |
---|
123 | execution.</returns> |
---|
124 | </method> |
---|
125 | |
---|
126 | <method name="operator!=" cv="const"> |
---|
127 | <type>bool</type> |
---|
128 | |
---|
129 | <parameter name="rhs"> |
---|
130 | <type>const thread&</type> |
---|
131 | </parameter> |
---|
132 | |
---|
133 | <requires>The thread is non-terminated or <code>*this</code> |
---|
134 | is joinable.</requires> |
---|
135 | |
---|
136 | <returns><code>!(*this==rhs)</code>.</returns> |
---|
137 | </method> |
---|
138 | </method-group> |
---|
139 | |
---|
140 | <method-group name="modifier"> |
---|
141 | <method name="join"> |
---|
142 | <type>void</type> |
---|
143 | |
---|
144 | <requires><code>*this</code> is joinable.</requires> |
---|
145 | |
---|
146 | <effects>The current thread of execution blocks until the |
---|
147 | initial function of the thread of execution represented by |
---|
148 | <code>*this</code> finishes and all resources are |
---|
149 | reclaimed.</effects> |
---|
150 | |
---|
151 | <postcondition><code>*this</code> is non-joinable.</postcondition> |
---|
152 | |
---|
153 | <notes>If <code>*this == thread()</code> the result is |
---|
154 | implementation-defined. If the implementation doesn't |
---|
155 | detect this the result will be |
---|
156 | <link linkend="thread.glossary.deadlock">deadlock</link>. |
---|
157 | </notes> |
---|
158 | </method> |
---|
159 | </method-group> |
---|
160 | |
---|
161 | <method-group name="static"> |
---|
162 | <method name="sleep" specifiers="static"> |
---|
163 | <type>void</type> |
---|
164 | |
---|
165 | <parameter name="xt"> |
---|
166 | <paramtype>const <classname>xtime</classname>&</paramtype> |
---|
167 | </parameter> |
---|
168 | |
---|
169 | <effects>The current thread of execution blocks until |
---|
170 | <code>xt</code> is reached.</effects> |
---|
171 | </method> |
---|
172 | |
---|
173 | <method name="yield" specifiers="static"> |
---|
174 | <type>void</type> |
---|
175 | |
---|
176 | <effects>The current thread of execution is placed in the |
---|
177 | <link linkend="thread.glossary.thread-state">ready</link> |
---|
178 | state.</effects> |
---|
179 | |
---|
180 | <notes> |
---|
181 | <simpara>Allow the current thread to give up the rest of its |
---|
182 | time slice (or other scheduling quota) to another thread. |
---|
183 | Particularly useful in non-preemptive implementations.</simpara> |
---|
184 | </notes> |
---|
185 | </method> |
---|
186 | </method-group> |
---|
187 | </class> |
---|
188 | |
---|
189 | <class name="thread_group"> |
---|
190 | <purpose> |
---|
191 | The <classname>thread_group</classname> class provides a container |
---|
192 | for easy grouping of threads to simplify several common thread |
---|
193 | creation and management idioms. |
---|
194 | </purpose> |
---|
195 | |
---|
196 | <inherit access="private"> |
---|
197 | <type><classname>boost::noncopyable</classname></type> |
---|
198 | <purpose>Exposition only</purpose> |
---|
199 | </inherit> |
---|
200 | |
---|
201 | |
---|
202 | <constructor> |
---|
203 | <effects>Constructs an empty <classname>thread_group</classname> |
---|
204 | container.</effects> |
---|
205 | </constructor> |
---|
206 | |
---|
207 | <destructor> |
---|
208 | <effects>Destroys each contained thread object. Destroys <code>*this</code>.</effects> |
---|
209 | |
---|
210 | <notes>Behavior is undefined if another thread references |
---|
211 | <code>*this </code> during the execution of the destructor. |
---|
212 | </notes> |
---|
213 | </destructor> |
---|
214 | |
---|
215 | <method-group name="modifier"> |
---|
216 | <method name="create_thread"> |
---|
217 | <type><classname>thread</classname>*</type> |
---|
218 | |
---|
219 | <parameter name="threadfunc"> |
---|
220 | <paramtype>const boost::function0<void>&</paramtype> |
---|
221 | </parameter> |
---|
222 | |
---|
223 | <effects>Creates a new <classname>thread</classname> object |
---|
224 | that executes <code>threadfunc</code> and adds it to the |
---|
225 | <code>thread_group</code> container object's list of managed |
---|
226 | <classname>thread</classname> objects.</effects> |
---|
227 | |
---|
228 | <returns>Pointer to the newly created |
---|
229 | <classname>thread</classname> object.</returns> |
---|
230 | </method> |
---|
231 | |
---|
232 | <method name="add_thread"> |
---|
233 | <type>void</type> |
---|
234 | |
---|
235 | <parameter name="thrd"> |
---|
236 | <paramtype><classname>thread</classname>*</paramtype> |
---|
237 | </parameter> |
---|
238 | |
---|
239 | <effects>Adds <code>thrd</code> to the |
---|
240 | <classname>thread_group</classname> object's list of managed |
---|
241 | <classname>thread</classname> objects. The <code>thrd</code> |
---|
242 | object must have been allocated via <code>operator new</code> and will |
---|
243 | be deleted when the group is destroyed.</effects> |
---|
244 | </method> |
---|
245 | |
---|
246 | <method name="remove_thread"> |
---|
247 | <type>void</type> |
---|
248 | |
---|
249 | <parameter name="thrd"> |
---|
250 | <paramtype><classname>thread</classname>*</paramtype> |
---|
251 | </parameter> |
---|
252 | |
---|
253 | <effects>Removes <code>thread</code> from <code>*this</code>'s |
---|
254 | list of managed <classname>thread</classname> objects.</effects> |
---|
255 | |
---|
256 | <throws><emphasis role="bold">???</emphasis> if |
---|
257 | <code>thrd</code> is not in <code>*this</code>'s list |
---|
258 | of managed <classname>thread</classname> objects.</throws> |
---|
259 | </method> |
---|
260 | |
---|
261 | <method name="join_all"> |
---|
262 | <type>void</type> |
---|
263 | |
---|
264 | <effects>Calls <code>join()</code> on each of the managed |
---|
265 | <classname>thread</classname> objects.</effects> |
---|
266 | </method> |
---|
267 | </method-group> |
---|
268 | </class> |
---|
269 | </namespace> |
---|
270 | </header> |
---|