File: readerwritermutex_concept.htm

package info (click to toggle)
tbb 4.2~20140122-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 21,492 kB
  • ctags: 21,278
  • sloc: cpp: 92,813; ansic: 9,775; asm: 1,070; makefile: 1,057; sh: 351; java: 226; objc: 98; pascal: 71; xml: 41
file content (518 lines) | stat: -rwxr-xr-x 15,502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<!DOCTYPE html
  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns:MSHelp="http://www.microsoft.com/MSHelp/" lang="en-us" xml:lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="DC.Type" content="reference">
<meta name="DC.Title" content="ReaderWriterMutex Concept">
<meta name="DC.subject" content="ReaderWriterMutex Concept">
<meta name="keywords" content="ReaderWriterMutex Concept">
<meta name="DC.Relation" scheme="URI" content="../../../reference/synchronization/mutexes.htm">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="readerwritermutex_concept">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../../intel_css_styles.css">
<title>ReaderWriterMutex Concept</title>
</head>
<body id="readerwritermutex_concept">
 <!-- ==============(Start:NavScript)================= -->
 <script src="..\..\..\NavScript.js" language="JavaScript1.2" type="text/javascript"></script>
 <script language="JavaScript1.2" type="text/javascript">WriteNavLink(3);</script>
 <!-- ==============(End:NavScript)================= -->
<a name="readerwritermutex_concept"><!-- --></a>

 
  <h1 class="topictitle1">ReaderWriterMutex Concept</h1>
 
   
  <div> 
	 <div class="section"> 
		<p>The ReaderWriterMutex concept extends the Mutex
		  Concept to include the notion of reader-writer locks. It introduces a boolean
		  parameter 
		  <samp class="codeph">write</samp> that specifies whether a writer lock
		  (<samp class="codeph">write</samp> =true) or reader lock (<samp class="codeph">write</samp> =false)
		  is being requested. Multiple reader locks can be held simultaneously on a
		  ReaderWriterMutex if it does not have a writer lock on it. A writer lock on a
		  ReaderWriterMutex excludes all other threads from holding a lock on the mutex
		  at the same time. 
		</p>
 
		<p> The following table shows the requirements for a
		  ReaderWriterMutex 
		  <samp class="codeph">RW</samp>. They form a superset of the Mutex Concept. 
		</p>
 
		
<div class="tablenoborder"><a name="tbl28"><!-- --></a><table cellpadding="4" summary="" id="tbl28" width="100%" frame="hsides" border="1" rules="all"><caption><span class="tablecap">ReaderWriterMutex Concept</span></caption> 
		   
		   
		  <thead align="left">
			 <tr> 
				<th class="cellrowborder" valign="top" width="NaN%" id="d101181e52"> 
				  <p>Pseudo-Signature 
				  </p>
 
				</th>
 
				<th class="row-nocellborder" valign="top" width="NaN%" id="d101181e58"> 
				  <p>Semantics 
				  </p>
 
				</th>
 
			 </tr>
</thead>

		  <tbody> 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Construct unlocked mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">~RW()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Destroy unlocked mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">typename RW::scoped_lock</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Corresponding scoped-lock type. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW::scoped_lock()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Construct lock without acquiring mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW::scoped_lock(RW&amp;, bool
						write=true)</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Construct lock and acquire lock on mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW::~scoped_lock()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Release lock (if acquired). 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW::scoped_lock::acquire(RW&amp;,bool
						write=true)</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Acquire lock on mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">bool
						RW::scoped_lock::try_acquire(RW&amp;, bool write=true)</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Try to acquire lock on mutex. Return 
					 <samp class="codeph">true</samp> if lock acquired, 
					 <samp class="codeph">false</samp> otherwise. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">RW::scoped_lock::release()</samp>
					 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Release lock. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">bool
						RW::scoped_lock::upgrade_to_writer()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Change reader lock to writer lock. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">bool
						RW::scoped_lock::downgrade_to_reader()</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>Change writer lock to reader lock. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">static const bool RW::is_rw_mutex =
						true</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>True. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">static const bool
						RW::is_recursive_mutex</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>True if mutex is recursive; false
					 otherwise. For all current reader-writer mutexes, false. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="NaN%" headers="d101181e52 "> 
				  <p><samp class="codeph">static const bool
						RW::is_fair_mutex</samp> 
				  </p>
 
				</td>
 
				<td class="row-nocellborder" valign="top" width="NaN%" headers="d101181e58 "> 
				  <p>True if mutex is fair; false otherwise. 
				  </p>
 
				</td>
 
			 </tr>
 
		  </tbody>
 
		</table>
</div>
 
	 </div>
 
	 
<div class="tablenoborder"><table cellpadding="4" summary="" frame="border" border="1" cellspacing="0" rules="all"><span class="tabledesc">The following table provides explain the semantics of the
		  ReaderWriterMutex concept in detail. 
		</span><thead align="left"> 
			 <tr> 
				<th class="cellrowborder" valign="top" width="33.89830508474576%" id="d101181e329">Member 
				</th>
 
				<th class="cellrowborder" valign="top" width="66.10169491525423%" id="d101181e332">Description 
				</th>
 
			 </tr>
</thead>
 
		  <tbody> 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">Model Types</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Classes 
					 <samp class="codeph"><samp class="codeph">spin_rw_mutex</samp></samp> and 
					 <samp class="codeph"><samp class="codeph">queuing_rw_mutex</samp></samp> model the
					 ReaderWriterMutex concept. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">ReaderWriterMutex()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Constructs unlocked 
					 <samp class="codeph">ReaderWriterMutex</samp>. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">~ReaderWriterMutex()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Destroys unlocked 
					 <samp class="codeph">ReaderWriterMutex</samp>. The effect of destroying a
					 locked 
					 <samp class="codeph">ReaderWriterMutex</samp> is undefined. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">ReaderWriterMutex::scoped_lock()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Constructs a 
					 <samp class="codeph">scoped_lock</samp> object that does not hold a lock
					 on any mutex. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword"> ReaderWriterMutex::scoped_lock(
					 ReaderWriterMutex&amp; rw, bool write =true)</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Constructs a 
					 <samp class="codeph">scoped_lock</samp> object that acquires a lock on
					 mutex 
					 <em>rw</em>. The lock is a writer lock if 
					 <samp class="codeph"><em>write</em></samp> is true; a reader lock otherwise.
					 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">ReaderWriterMutex::~scoped_lock()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>If the object holds a lock on a 
					 <samp class="codeph">ReaderWriterMutex</samp>, releases the lock. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">void ReaderWriterMutex::
					 scoped_lock:: acquire( ReaderWriterMutex&amp; rw,&nbsp; bool write=true )</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Acquires a lock on mutex 
					 <em>rw</em>. The lock is a writer lock if 
					 <samp class="codeph"><em>write</em></samp> is true; a reader lock otherwise.
					 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword"> bool ReaderWriterMutex::
					 scoped_lock::try_acquire( ReaderWriterMutex&amp; rw, bool write=true
					 )</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Attempts to acquire a lock on mutex 
					 <em>rw</em>. The lock is a writer lock if 
					 <samp class="codeph"><em>write</em></samp> is true; a reader lock otherwise.
					 
				  </p>
 
				  <p><strong>Returns</strong>: 
					 <samp class="codeph">true</samp> if the lock is acquired, 
					 <samp class="codeph">false</samp> otherwise. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword"> void ReaderWriterMutex::
					 scoped_lock::release()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Releases lock. The effect is undefined if
					 no lock is held. 
				  </p>
 
				  <p><strong>Returns</strong>: 
					 <samp class="codeph">false</samp> if lock was released in favor of another
					 upgrade request and then reacquired; 
					 <samp class="codeph">true</samp> otherwise. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">bool ReaderWriterMutex::
					 scoped_lock::upgrade_to_writer()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Changes reader lock to a writer lock. The
					 effect is undefined if the object does not already hold a reader lock. 
				  </p>
 
				  <p><strong>Returns</strong>: 
					 <samp class="codeph">false</samp> if lock was released and reacquired; 
					 <samp class="codeph">true</samp> otherwise. 
				  </p>
 
				</td>
 
			 </tr>
 
			 <tr> 
				<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d101181e329 "><span class="keyword">bool ReaderWriterMutex::
					 scoped_lock::downgrade_to_reader()</span> 
				</td>
 
				<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d101181e332 "> 
				  <p>Changes writer lock to a reader lock. The
					 effect is undefined if the object does not already hold a writer lock. 
				  </p>
 
				  <p><strong>Returns</strong>: 
					 <samp class="codeph">false</samp> if lock was released and reacquired; 
					 <samp class="codeph">true</samp> otherwise. 
				  </p>
 
				  <p>Intel's current implementations for 
					 <samp class="codeph">spin_rw_mutex</samp> and 
					 <samp class="codeph">queuing_rw_mutex</samp> always return 
					 <samp class="codeph">true</samp>. Different implementations might
					 sometimes return 
					 <samp class="codeph">false</samp>. 
				  </p>
 
				</td>
 
			 </tr>
 
		  </tbody>
 
		</table>
</div>
 
  </div>
 

<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong>&nbsp;<a href="../../../reference/synchronization/mutexes.htm">Mutexes</a></div>
</div>
<div></div>

</body>
</html>