Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/thread/doc/condition-ref.xml @ 29

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

updated boost from 1_33_1 to 1_34_1

File size: 8.4 KB
Line 
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/condition.hpp"
12  last-revision="$Date: 2006/10/15 14:52:53 $">
13  <namespace name="boost">
14    <class name="condition">
15      <inherit access="private">
16        <type><classname>boost::noncopyable</classname></type>
17        <purpose>Exposition only</purpose>
18      </inherit>
19
20      <purpose>
21        <para>An object of class <classname>condition</classname> is a
22          synchronization primitive used to cause a thread to wait until a
23          particular shared-data condition (or time) is met.</para>
24      </purpose>
25
26      <description>
27        <para>A <classname>condition</classname> object is always used in
28          conjunction with a <link linkend="thread.concepts.mutexes">mutex</link>
29          object (an object whose type is a model of a <link
30            linkend="thread.concepts.Mutex">Mutex</link> or one of its
31          refinements). The mutex object must be locked prior to waiting on the
32          condition, which is verified by passing a lock object (an object whose
33          type is a model of <link linkend="thread.concepts.Lock">Lock</link> or
34          one of its refinements) to the <classname>condition</classname> object's
35          wait functions. Upon blocking on the <classname>condition</classname>
36          object, the thread unlocks the mutex object. When the thread returns
37          from a call to one of the <classname>condition</classname> object's wait
38          functions the mutex object is again locked. The tricky unlock/lock
39          sequence is performed automatically by the
40          <classname>condition</classname> object's wait functions.</para>
41        <para>The <classname>condition</classname> type is often used to
42          implement the Monitor Object and other important patterns (see
43          &cite.SchmidtStalRohnertBuschmann; and &cite.Hoare74;). Monitors are one
44          of the most important patterns for creating reliable multithreaded
45          programs.</para>
46        <para>See <xref linkend="thread.glossary"/> for definitions of <link
47            linkend="thread.glossary.thread-state">thread states</link>
48          blocked and ready. Note that "waiting" is a synonym for blocked.</para>
49      </description>
50
51      <constructor>
52        <effects><simpara>Constructs a <classname>condition</classname>
53            object.</simpara></effects>
54      </constructor>
55
56      <destructor>
57        <effects><simpara>Destroys <code>*this</code>.</simpara></effects>
58      </destructor>
59
60      <method-group name="notification">
61        <method name="notify_one">
62          <type>void</type>
63          <effects><simpara>If there is a thread waiting on <code>*this</code>,
64              change that thread's state to ready. Otherwise there is no
65              effect.</simpara></effects>
66          <notes><simpara>If more than one thread is waiting on <code>*this</code>,
67              it is unspecified which is made ready. After returning to a ready
68              state the notified thread must still acquire the mutex again (which
69              occurs within the call to one of the <classname>condition</classname>
70              object's wait functions.)</simpara></notes>
71        </method>
72
73        <method name="notify_all">
74          <type>void</type>
75          <effects><simpara>Change the state of all threads waiting on
76              <code>*this</code> to ready. If there are no waiting threads,
77              <code>notify_all()</code> has no effect.</simpara></effects>
78        </method>
79      </method-group>
80
81      <method-group name="waiting">
82        <method name="wait">
83          <template>
84            <template-type-parameter name="ScopedLock"/>
85          </template>
86
87          <type>void</type>
88
89          <parameter name="lock">
90            <paramtype>ScopedLock&amp;</paramtype>
91          </parameter>
92
93          <requires><simpara><code>ScopedLock</code> meets the <link
94                linkend="thread.concepts.ScopedLock">ScopedLock</link>
95              requirements.</simpara></requires>
96          <effects><simpara>Releases the lock on the <link
97                linkend="thread.concepts.mutexes">mutex object</link>
98              associated with <code>lock</code>, blocks the current thread of execution
99              until readied by a call to <code>this->notify_one()</code>
100              or<code> this->notify_all()</code>, and then reacquires the
101              lock.</simpara></effects>
102          <throws><simpara><classname>lock_error</classname> if
103              <code>!lock.locked()</code></simpara></throws>
104        </method>
105
106        <method name="wait">
107          <template>
108            <template-type-parameter name="ScopedLock"/>
109            <template-type-parameter name="Pred"/>
110          </template>
111
112          <type>void</type>
113
114          <parameter name="lock">
115            <paramtype>ScopedLock&amp;</paramtype>
116          </parameter>
117
118          <parameter name="pred">
119            <paramtype>Pred</paramtype>
120          </parameter>
121
122          <requires><simpara><code>ScopedLock</code> meets the <link
123                linkend="thread.concepts.ScopedLock">ScopedLock</link>
124              requirements and the return from <code>pred()</code> is
125              convertible to <code>bool</code>.</simpara></requires>
126          <effects><simpara>As if: <code>while (!pred())
127                wait(lock)</code></simpara></effects>
128          <throws><simpara><classname>lock_error</classname> if
129              <code>!lock.locked()</code></simpara></throws>
130        </method>
131
132        <method name="timed_wait">
133          <template>
134            <template-type-parameter name="ScopedLock"/>
135          </template>
136
137          <type>bool</type>
138
139          <parameter name="lock">
140            <paramtype>ScopedLock&amp;</paramtype>
141          </parameter>
142
143          <parameter name="xt">
144            <paramtype>const <classname>boost::xtime</classname>&amp;</paramtype>
145          </parameter>
146
147          <requires><simpara><code>ScopedLock</code> meets the <link
148                linkend="thread.concepts.ScopedLock">ScopedLock</link>
149              requirements.</simpara></requires>
150          <effects><simpara>Releases the lock on the <link
151                linkend="thread.concepts.mutexes">mutex object</link>
152              associated with <code>lock</code>, blocks the current thread of execution
153              until readied by a call to <code>this->notify_one()</code>
154              or<code> this->notify_all()</code>, or until time <code>xt</code> 
155              is reached, and then reacquires the lock.</simpara></effects>
156          <returns><simpara><code>false</code> if time <code>xt</code> is reached,
157              otherwise <code>true</code>.</simpara></returns>
158          <throws><simpara><classname>lock_error</classname> if
159              <code>!lock.locked()</code></simpara></throws>
160        </method>
161
162        <method name="timed_wait">
163          <template>
164            <template-type-parameter name="ScopedLock"/>
165            <template-type-parameter name="Pred"/>
166          </template>
167
168          <type>bool</type>
169
170          <parameter name="lock">
171            <paramtype>ScopedLock&amp;</paramtype>
172          </parameter>
173
174          <parameter name="xt">
175            <paramtype>const <classname>boost::xtime</classname>&amp;</paramtype>
176          </parameter>
177
178          <parameter name="pred">
179            <paramtype>Pred</paramtype>
180          </parameter>
181
182          <requires><simpara><code>ScopedLock</code> meets the <link
183                linkend="thread.concepts.ScopedLock">ScopedLock</link>
184              requirements and the return from <code>pred()</code> is
185              convertible to <code>bool</code>.</simpara></requires>
186          <effects><simpara>As if: <code>while (!pred()) { if (!timed_wait(lock,
187                xt)) return false; } return true;</code></simpara></effects>
188          <returns><simpara><code>false</code> if <code>xt</code> is reached,
189              otherwise <code>true</code>.</simpara></returns>
190          <throws><simpara><classname>lock_error</classname> if
191              <code>!lock.locked()</code></simpara></throws>
192        </method>
193      </method-group>
194    </class>
195  </namespace>
196</header>
Note: See TracBrowser for help on using the repository browser.