1 | <html> |
---|
2 | <head> |
---|
3 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
---|
4 | <title>Class read_write_mutex</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.read_write_mutex.hpp" title="Header <boost/thread/read_write_mutex.hpp>"> |
---|
9 | <link rel="prev" href="read_write_scheduling_policy/read_write_scheduling_policy.html" title="Type read_write_scheduling_policy"> |
---|
10 | <link rel="next" href="try_read_write_mutex.html" title="Class try_read_write_mutex"> |
---|
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="read_write_scheduling_policy/read_write_scheduling_policy.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread/reference.html#header.boost.thread.read_write_mutex.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="try_read_write_mutex.html"><img src="../images/next.png" alt="Next"></a> |
---|
24 | </div> |
---|
25 | <div class="refentry" lang="en"> |
---|
26 | <a name="boost.read_write_mutex"></a><div class="titlepage"></div> |
---|
27 | <div class="refnamediv"> |
---|
28 | <h2><span class="refentrytitle">Class read_write_mutex</span></h2> |
---|
29 | <p>boost::read_write_mutex — <p>The <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> class is a model of the |
---|
30 | <a href="../thread/concepts.html#thread.concepts.ReadWriteMutex" title="ReadWriteMutex Concept">ReadWriteMutex</a> concept.</p><div class="note"><table border="0" summary="Note"> |
---|
31 | <tr> |
---|
32 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td> |
---|
33 | <th align="left">Note</th> |
---|
34 | </tr> |
---|
35 | <tr><td align="left" valign="top"> Unfortunately it turned out that the current implementation of Read/Write Mutex has |
---|
36 | some serious problems. So it was decided not to put this implementation into |
---|
37 | release grade code. Also discussions on the mailing list led to the |
---|
38 | conclusion that the current concepts need to be rethought. In particular |
---|
39 | the schedulings <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies.inter-class" title="Inter-Class Scheduling Policies"> |
---|
40 | Inter-Class Scheduling Policies</a> are deemed unnecessary. |
---|
41 | There seems to be common belief that a fair scheme suffices. |
---|
42 | The following documentation has been retained however, to give |
---|
43 | readers of this document the opportunity to study the original design. |
---|
44 | </td></tr> |
---|
45 | </table></div></p> |
---|
46 | </div> |
---|
47 | <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> |
---|
48 | <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"> |
---|
49 | <span class="bold"><strong>class</strong></span> read_write_mutex : <span class="bold"><strong>private</strong></span> boost::noncopyable, <span class="emphasis"><em>// Exposition only</em></span> |
---|
50 | <span class="bold"><strong>private</strong></span> boost::noncopyable <span class="emphasis"><em>// Exposition only</em></span> |
---|
51 | { |
---|
52 | <span class="bold"><strong>public</strong></span>: |
---|
53 | <span class="emphasis"><em>// types</em></span> |
---|
54 | <span class="bold"><strong>typedef</strong></span> <span class="emphasis"><em>implementation-defined</em></span> scoped_read_write_lock; |
---|
55 | <span class="bold"><strong>typedef</strong></span> <span class="emphasis"><em>implementation-defined</em></span> scoped_read_lock; |
---|
56 | <span class="bold"><strong>typedef</strong></span> <span class="emphasis"><em>implementation-defined</em></span> scoped_write_lock; |
---|
57 | |
---|
58 | <span class="emphasis"><em>// <a href="read_write_mutex.html#boost.read_write_mutexconstruct-copy-destruct">construct/copy/destruct</a></em></span> |
---|
59 | <a href="read_write_mutex.html#id1275854-bb">read_write_mutex</a>(boost::read_write_scheduling_policy); |
---|
60 | <a href="read_write_mutex.html#id1289193-bb">~read_write_mutex</a>(); |
---|
61 | };</pre></div> |
---|
62 | <div class="refsect1" lang="en"> |
---|
63 | <a name="id1741938"></a><h2>Description</h2> |
---|
64 | <p>The <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> class is a model of the |
---|
65 | <a href="../thread/concepts.html#thread.concepts.ReadWriteMutex" title="ReadWriteMutex Concept">ReadWriteMutex</a> concept. |
---|
66 | It should be used to synchronize access to shared resources using |
---|
67 | <a href="../thread/concepts.html#thread.concepts.read-write-locking-strategies.unspecified" title="Unspecified Locking Strategy">Unspecified</a> |
---|
68 | locking mechanics.</p> |
---|
69 | <p>For classes that model related mutex concepts, see |
---|
70 | <a href="try_read_write_mutex.html" title="Class try_read_write_mutex">try_read_write_mutex</a> and <a href="timed_read_write_mutex.html" title="Class timed_read_write_mutex">timed_read_write_mutex</a>.</p> |
---|
71 | <p>The <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> class supplies the following typedefs, |
---|
72 | which <a href="../thread/concepts.html#thread.concepts.read-write-lock-models" title="Lock Models">model</a> |
---|
73 | the specified locking strategies: |
---|
74 | |
---|
75 | </p> |
---|
76 | <div class="informaltable"><table class="table"> |
---|
77 | <colgroup> |
---|
78 | <col> |
---|
79 | <col> |
---|
80 | </colgroup> |
---|
81 | <thead><tr> |
---|
82 | <th align="left">Lock Name</th> |
---|
83 | <th align="left">Lock Concept</th> |
---|
84 | </tr></thead> |
---|
85 | <tbody> |
---|
86 | <tr> |
---|
87 | <td align="left">scoped_read_write_lock</td> |
---|
88 | <td align="left"><a href="../thread/concepts.html#thread.concepts.ScopedReadWriteLock" title="ScopedReadWriteLock Concept">ScopedReadWriteLock</a></td> |
---|
89 | </tr> |
---|
90 | <tr> |
---|
91 | <td align="left">scoped_read_lock</td> |
---|
92 | <td align="left"><a href="../thread/concepts.html#thread.concepts.ScopedLock" title="ScopedLock Concept">ScopedLock</a></td> |
---|
93 | </tr> |
---|
94 | <tr> |
---|
95 | <td align="left">scoped_write_lock</td> |
---|
96 | <td align="left"><a href="../thread/concepts.html#thread.concepts.ScopedLock" title="ScopedLock Concept">ScopedLock</a></td> |
---|
97 | </tr> |
---|
98 | </tbody> |
---|
99 | </table></div> |
---|
100 | <p> |
---|
101 | </p> |
---|
102 | <p>The <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> class uses an |
---|
103 | <a href="../thread/concepts.html#thread.concepts.read-write-locking-strategies.unspecified" title="Unspecified Locking Strategy">Unspecified</a> |
---|
104 | locking strategy, so attempts to recursively lock a <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> |
---|
105 | object or attempts to unlock one by threads that don't own a lock on it result in |
---|
106 | <span class="bold"><strong>undefined behavior</strong></span>. |
---|
107 | This strategy allows implementations to be as efficient as possible |
---|
108 | on any given platform. It is, however, recommended that |
---|
109 | implementations include debugging support to detect misuse when |
---|
110 | <code class="computeroutput">NDEBUG</code> is not defined.</p> |
---|
111 | <p>Like all |
---|
112 | <a href="../thread/concepts.html#thread.concepts.read-write-mutex-models" title="Mutex Models">read/write mutex models</a> |
---|
113 | in <span class="bold"><strong>Boost.Thread</strong></span>, <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> has two types of |
---|
114 | <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies" title="Scheduling Policies">scheduling policies</a>, an |
---|
115 | <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies.inter-class" title="Inter-Class Scheduling Policies">inter-class sheduling policy</a> |
---|
116 | between threads trying to obtain different types of locks and an |
---|
117 | <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies.intra-class" title="Intra-Class Scheduling Policies">intra-class sheduling policy</a> |
---|
118 | between threads trying to obtain the same type of lock. |
---|
119 | The <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> class allows the |
---|
120 | programmer to choose what |
---|
121 | <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies.inter-class" title="Inter-Class Scheduling Policies">inter-class sheduling policy</a> |
---|
122 | will be used; however, like all read/write mutex models, |
---|
123 | <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> leaves the |
---|
124 | <a href="../thread/concepts.html#thread.concepts.read-write-scheduling-policies.intra-class" title="Intra-Class Scheduling Policies">intra-class sheduling policy</a> as |
---|
125 | <a href="../thread/concepts.html#thread.concepts.read-write-locking-strategies.unspecified" title="Unspecified Locking Strategy">Unspecified</a>. |
---|
126 | </p> |
---|
127 | <div class="note"><table border="0" summary="Note"> |
---|
128 | <tr> |
---|
129 | <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../images/note.png"></td> |
---|
130 | <th align="left">Note</th> |
---|
131 | </tr> |
---|
132 | <tr><td align="left" valign="top">Self-deadlock is virtually guaranteed if a thread tries to |
---|
133 | lock the same <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> multiple times |
---|
134 | unless all locks are read-locks (but see below)</td></tr> |
---|
135 | </table></div> |
---|
136 | <div class="refsect2" lang="en"> |
---|
137 | <a name="id1742245"></a><h3> |
---|
138 | <a name="boost.read_write_mutexconstruct-copy-destruct"></a><code class="computeroutput">read_write_mutex</code> construct/copy/destruct</h3> |
---|
139 | <div class="orderedlist"><ol type="1"> |
---|
140 | <li> |
---|
141 | <pre class="literallayout"><a name="id1275854-bb"></a>read_write_mutex(boost::read_write_scheduling_policy count);</pre> |
---|
142 | <div class="variablelist"><table border="0"> |
---|
143 | <col align="left" valign="top"> |
---|
144 | <tbody> |
---|
145 | <tr> |
---|
146 | <td> |
---|
147 | <span class="term">Effects:</span></td> |
---|
148 | <td>Constructs a <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> object. |
---|
149 | </td> |
---|
150 | </tr> |
---|
151 | <tr> |
---|
152 | <td> |
---|
153 | <span class="term">Postconditions:</span></td> |
---|
154 | <td> |
---|
155 | <code class="computeroutput">*this</code> is in an unlocked state. |
---|
156 | </td> |
---|
157 | </tr> |
---|
158 | </tbody> |
---|
159 | </table></div> |
---|
160 | </li> |
---|
161 | <li> |
---|
162 | <pre class="literallayout"><a name="id1289193-bb"></a>~read_write_mutex();</pre> |
---|
163 | <div class="variablelist"><table border="0"> |
---|
164 | <col align="left" valign="top"> |
---|
165 | <tbody> |
---|
166 | <tr> |
---|
167 | <td> |
---|
168 | <span class="term">Effects:</span></td> |
---|
169 | <td>Destroys a <a href="read_write_mutex.html" title="Class read_write_mutex">read_write_mutex</a> object.</td> |
---|
170 | </tr> |
---|
171 | <tr> |
---|
172 | <td> |
---|
173 | <span class="term">Requires:</span></td> |
---|
174 | <td> |
---|
175 | <code class="computeroutput">*this</code> is in an unlocked state.</td> |
---|
176 | </tr> |
---|
177 | <tr> |
---|
178 | <td> |
---|
179 | <span class="term">Notes:</span></td> |
---|
180 | <td> |
---|
181 | <span class="bold"><strong>Danger:</strong></span> Destruction of a |
---|
182 | locked mutex is a serious programming error resulting in undefined |
---|
183 | behavior such as a program crash.</td> |
---|
184 | </tr> |
---|
185 | </tbody> |
---|
186 | </table></div> |
---|
187 | </li> |
---|
188 | </ol></div> |
---|
189 | </div> |
---|
190 | </div> |
---|
191 | </div> |
---|
192 | <table width="100%"><tr> |
---|
193 | <td align="left"></td> |
---|
194 | <td align="right"><small>Copyright © 2001-2003 William E. Kempf</small></td> |
---|
195 | </tr></table> |
---|
196 | <hr> |
---|
197 | <div class="spirit-nav"> |
---|
198 | <a accesskey="p" href="read_write_scheduling_policy/read_write_scheduling_policy.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../thread/reference.html#header.boost.thread.read_write_mutex.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="try_read_write_mutex.html"><img src="../images/next.png" alt="Next"></a> |
---|
199 | </div> |
---|
200 | </body> |
---|
201 | </html> |
---|