1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0.1 Transitional//EN">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1">
6 <title>Boost.Flyweight Documentation - Locking policies reference
</title>
7 <link rel=
"stylesheet" href=
"../style.css" type=
"text/css">
8 <link rel=
"start" href=
"../index.html">
9 <link rel=
"prev" href=
"factories.html">
10 <link rel=
"up" href=
"index.html">
11 <link rel=
"next" href=
"tracking.html">
15 <h1><img src=
"../../../../boost.png" alt=
"Boost logo" align=
16 "middle" width=
"277" height=
"86">Boost.Flyweight
17 Locking policies reference
</h1>
19 <div class=
"prev_link"><a href=
"holders.html"><img src=
"../prev.gif" alt=
"holders" border=
"0"><br>
22 <div class=
"up_link"><a href=
"index.html"><img src=
"../up.gif" alt=
"Boost.Flyweight reference" border=
"0"><br>
23 Boost.Flyweight reference
25 <div class=
"next_link"><a href=
"tracking.html"><img src=
"../next.gif" alt=
"tracking policies" border=
"0"><br>
27 </a></div><br clear=
"all" style=
"clear: all;">
34 <li><a href=
"#preliminary">Preliminary concepts
</a></li>
35 <li><a href=
"#locking">Locking policies
</a></li>
36 <li><a href=
"#locking_tag_synopsis">Header
37 <code>"boost/flyweight/locking_tag.hpp"</code> synopsis
</a>
39 <li><a href=
"#is_locking">Class template
<code>is_locking
</code></a></li>
40 <li><a href=
"#locking_construct">Class template
<code>locking
</code></a></li>
43 <li><a href=
"#simple_locking_fwd_synopsis">Header
44 <code>"boost/flyweight/simple_locking_fwd.hpp"</code> synopsis
</a>
46 <li><a href=
"#simple_locking_synopsis">Header
47 <code>"boost/flyweight/simple_locking.hpp"</code> synopsis
</a>
49 <li><a href=
"#simple_locking">Class
<code>simple_locking
</code></a></li>
52 <li><a href=
"#no_locking_fwd_synopsis">Header
53 <code>"boost/flyweight/no_locking_fwd.hpp"</code> synopsis
</a>
55 <li><a href=
"#no_locking_synopsis">Header
56 <code>"boost/flyweight/no_locking.hpp"</code> synopsis
</a>
58 <li><a href=
"#no_locking">Class
<code>no_locking
</code></a></li>
63 <h2><a name=
"preliminary">Preliminary concepts
</a></h2>
66 A
<i>mutex
</i> is a type whose objects can be in either of two states, called
67 locked and unlocked, with the property that when a thread A has locked a
68 mutex
<code>m
</code> and a different thread B tries to lock
<code>m
</code>,
69 B is blocked until A unlocks
<code>m
</code>. Additionally, a mutex is said to
70 support
<i>recursive locking
</i> if a thread can succesfully invoke the locking
71 operation for a mutex already locked by this same thread; in this case, it is
72 required that the thread execute as many unlock operations as lock
73 operations it has performed for the mutex to become effectively unlocked.
74 A
<i>scoped lock
</i> is a
75 type associated to some mutex type whose objects do the locking/unlocking
76 of a mutex on construction/destruction time.
80 In the following table,
<code>Mutex
</code> is a mutex type,
<code>m
</code>
81 is an object of type
<code>Mutex
</code>,
<code>Lock
</code> is a scoped lock
82 associated to
<code>Mutex
</code> and
<code>lk
</code> is a value of
86 <table cellspacing=
"0">
87 <caption><b>Mutex and Scoped Lock requirements.
</b></caption>
89 <th align=
"center">expression
</th>
90 <th align=
"center">return type
</th>
91 <th align=
"center">assertion/note
<br>pre/post-condition
</th>
94 <td><code>Mutex m;
</code></td>
96 <td>Post:
<code>m
</code> is unlocked.
100 <td><code>(
&m)-
>~Mutex();
</code></td>
101 <td><code>void
</code></td>
102 <td>Pre:
<code>m
</code> is unlocked.
</td>
105 <td><code>Lock lk(m);
</code></td>
107 <td>Associates
<code>m
</code> to
<code>lk
</code> and locks
<code>m
</code>.
</td>
110 <td><code>(
&lk)-
>~Lock();
</code></td>
111 <td><code>void
</code></td>
112 <td>Unlocks the mutex associated to
<code>lk
</code>.
</td>
118 These concepts are very similar, but not entirely equivalent, to
119 the homonym ones described in the
120 <a href=
"../../../../doc/html/thread/synchronization.html#thread.synchronization.mutex_concepts">Boost Thread
124 <h2><a name=
"locking">Locking policies
</a></h2>
127 <i>Locking policies
</i> describe a mutex type and an associated
129 <a href=
"flyweight.html#flyweight"><code>flyweight
</code></a> uses a given locking
130 policy to synchronize the access to its internal
131 <a href=
"factories.html#factory">factory
</a>.
135 A type
<code>Locking
</code> is a locking policy if:
137 <li>One of the following conditions is satisfied:
139 <li><a href=
"#is_locking"><code>is_locking
<Locking
>::type
</code></a> is
140 <a href=
"../../../mpl/doc/refmanual/bool.html"><code>boost::mpl::true_
</code></a>,
</li>
141 <li><code>Locking
</code> is of the form
142 <a href=
"#locking_construct"><code>locking
<Locking'
></code></a>.
</li>
145 <li>The type
<code>Locking::mutex_type
</code> (or
146 <code>Locking'::mutex_type
</code> if (b) applies) is a
147 model of
<a href=
"#preliminary"><code>Mutex
</code></a>
148 and supports recursive locking.
150 <li>The type
<code>Locking::lock_type
</code> (or
151 <code>Locking'::lock_type
</code> if (b) applies) is a
152 <a href=
"#preliminary"><code>Scoped Lock
</code></a> of
153 the mutex referred to above.
158 <h2><a name=
"locking_tag_synopsis">Header
159 <a href=
"../../../../boost/flyweight/locking_tag.hpp"><code>"boost/flyweight/locking_tag.hpp"</code></a> synopsis
</a></h2>
162 <span class=keyword
>namespace
</span> <span class=identifier
>boost
</span><span class=special
>{
</span>
164 <span class=keyword
>namespace
</span> <span class=identifier
>flyweights
</span><span class=special
>{
</span>
166 <span class=keyword
>struct
</span> <span class=identifier
>locking_marker
</span><span class=special
>;
</span>
168 <span class=keyword
>template
</span><span class=special
><</span><span class=keyword
>typename
</span> <span class=identifier
>T
</span><span class=special
>></span>
169 <span class=keyword
>struct
</span> <span class=identifier
>is_locking
</span>
171 <span class=keyword
>template
</span><span class=special
><</span><span class=keyword
>typename
</span> <span class=identifier
>T
</span><span class=special
>></span>
172 <span class=keyword
>struct
</span> <span class=identifier
>locking
</span><span class=special
>;
</span>
174 <span class=special
>}
</span> <span class=comment
>// namespace boost::flyweights
</span>
176 <span class=special
>}
</span> <span class=comment
>// namespace boost
</span>
179 <h3><a name=
"is_locking">Class template
<code>is_locking
</code></a></h3>
182 Unless specialized by the user,
<code>is_locking
<T
>::type
</code> is
183 <a href=
"../../../mpl/doc/refmanual/bool.html"><code>boost::mpl::true_
</code></a>
184 if
<code>T
</code> is derived from
<code>locking_marker
</code>, and it is
185 <a href=
"../../../mpl/doc/refmanual/bool.html"><code>boost::mpl::false_
</code></a>
189 <h3><a name=
"locking_construct">Class template
<code>locking
</code></a></h3>
192 <code>locking
<T
></code> is a syntactic construct meant to indicate
193 that
<code>T
</code> is a locking policy without resorting to the
194 mechanisms provided by the
<code>is_locking
</code> class template.
197 <h2><a name=
"simple_locking_fwd_synopsis">Header
198 <a href=
"../../../../boost/flyweight/simple_locking_fwd.hpp"><code>"boost/flyweight/simple_locking_fwd.hpp"</code></a> synopsis
</a></h2>
201 <span class=keyword
>namespace
</span> <span class=identifier
>boost
</span><span class=special
>{
</span>
203 <span class=keyword
>namespace
</span> <span class=identifier
>flyweights
</span><span class=special
>{
</span>
205 <span class=keyword
>struct
</span> <span class=identifier
>simple_locking
</span><span class=special
>;
</span>
207 <span class=special
>}
</span> <span class=comment
>// namespace boost::flyweights
</span>
209 <span class=special
>}
</span> <span class=comment
>// namespace boost
</span>
213 <code>simple_locking_fwd.hpp
</code> forward declares the class
214 <a href=
"#simple_locking"><code>simple_locking
</code></a>.
217 <h2><a name=
"simple_locking_synopsis">Header
218 <a href=
"../../../../boost/flyweight/simple_locking.hpp"><code>"boost/flyweight/simple_locking.hpp"</code></a> synopsis
</a></h2>
220 <h3><a name=
"simple_locking">Class
<code>simple_locking
</code></a></h3>
223 <a href=
"#locking"><code>Locking Policy
</code></a> that specifies a basic
224 mutex type based on the simplest synchronization mechanisms provided by
225 the environment; When no threading capabilities are available,
226 <code>simple_locking
</code> specifies a dummy type without actual
227 synchronization capabilities.
230 <h2><a name=
"no_locking_fwd_synopsis">Header
231 <a href=
"../../../../boost/flyweight/no_locking_fwd.hpp"><code>"boost/flyweight/no_locking_fwd.hpp"</code></a> synopsis
</a></h2>
234 <span class=keyword
>namespace
</span> <span class=identifier
>boost
</span><span class=special
>{
</span>
236 <span class=keyword
>namespace
</span> <span class=identifier
>flyweights
</span><span class=special
>{
</span>
238 <span class=keyword
>struct
</span> <span class=identifier
>no_locking
</span><span class=special
>;
</span>
240 <span class=special
>}
</span> <span class=comment
>// namespace boost::flyweights
</span>
242 <span class=special
>}
</span> <span class=comment
>// namespace boost
</span>
246 <code>no_locking_fwd.hpp
</code> forward declares the class
247 <a href=
"#no_locking"><code>no_locking
</code></a>.
250 <h2><a name=
"no_locking_synopsis">Header
251 <a href=
"../../../../boost/flyweight/no_locking.hpp"><code>"boost/flyweight/no_locking.hpp"</code></a> synopsis
</a></h2>
253 <h3><a name=
"no_locking">Class
<code>no_locking
</code></a></h3>
256 Null
<a href=
"#locking"><code>Locking Policy
</code></a>: it specifies a dummy
257 type that satisfies the formal requirements for the
258 <a href=
"#preliminary"><code>Mutex
</code></a> concept but does not perform
259 thread blocking.
<code>no_locking
</code> should only be used in single-threaded
265 <div class=
"prev_link"><a href=
"holders.html"><img src=
"../prev.gif" alt=
"holders" border=
"0"><br>
268 <div class=
"up_link"><a href=
"index.html"><img src=
"../up.gif" alt=
"Boost.Flyweight reference" border=
"0"><br>
269 Boost.Flyweight reference
271 <div class=
"next_link"><a href=
"tracking.html"><img src=
"../next.gif" alt=
"tracking policies" border=
"0"><br>
273 </a></div><br clear=
"all" style=
"clear: all;">
277 <p>Revised March
9th
2010</p>
279 <p>© Copyright
2006-
2010 Joaqu
ín M L
ópez Mu
ñoz.
280 Distributed under the Boost Software
281 License, Version
1.0. (See accompanying file
<a href=
"../../../../LICENSE_1_0.txt">
282 LICENSE_1_0.txt
</a> or copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt">
283 http://www.boost.org/LICENSE_1_0.txt
</a>)