SCIRun
5.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
Core
Thread
Legacy
CrowdMonitor.h
Go to the documentation of this file.
1
/*
2
For more information, please see: http://software.sci.utah.edu
3
4
The MIT License
5
6
Copyright (c) 2009 Scientific Computing and Imaging Institute,
7
University of Utah.
8
9
10
Permission is hereby granted, free of charge, to any person obtaining a
11
copy of this software and associated documentation files (the "Software"),
12
to deal in the Software without restriction, including without limitation
13
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
and/or sell copies of the Software, and to permit persons to whom the
15
Software is furnished to do so, subject to the following conditions:
16
17
The above copyright notice and this permission notice shall be included
18
in all copies or substantial portions of the Software.
19
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26
DEALINGS IN THE SOFTWARE.
27
*/
28
29
30
31
///
32
///@file CrowdMonitor.h
33
///@brief Multiple reader/single writer locks
34
///
35
///@author Steve Parker
36
/// Department of Computer Science
37
/// University of Utah
38
///@date June 1997
39
///
40
41
#ifndef Core_Thread_CrowdMonitor_h
42
#define Core_Thread_CrowdMonitor_h
43
44
#include <
Core/Thread/Legacy/share.h
>
45
46
namespace
SCIRun {
47
struct
CrowdMonitor_private;
48
/**************************************
49
50
@class
51
CrowdMonitor
52
53
KEYWORDS
54
Thread
55
56
@details
57
Multiple reader, single writer synchronization primitive. Some
58
applications do not need the strict level of synchronization
59
provided by the <b>Mutex</b>. The <b>CrowdMonitor</b> relaxes
60
the synchronization by allowing multiple threads access to a
61
resource (usually a data area), on the condition that the thread
62
will only read the data. When a thread needs to write the data,
63
it can access the monitor in write mode (using <i>writeLock</i>).
64
At any given time, one writer thread can be active, or multiple
65
reader threads can be active. <b>CrowdMonitor</b> guards against
66
multiple writers accessing a data, and against a thread writing
67
to the data while other threads are reading it.
68
69
WARNING
70
<p> Calling <i>readLock</i> within a <i>writeLock/write_unlock</i>
71
section may result in a deadlock. Likewise, calling <i>writeLock</i>
72
within a <i>readLock/readUnlock</i> section may result in a deadlock.
73
Calling <i>readUnlock</i> or <i>writeUnlock</i> when the lock is
74
not held is not legal and may result in undefined behavior.
75
76
****************************************/
77
78
class
SCISHARE
CrowdMonitor
{
79
public
:
80
//////////
81
/// Create and initialize the CrowdMonitor. <i>name</i> should
82
/// be a static which describes the primitive for debugging
83
/// purposes.
84
CrowdMonitor
(
const
char
*
name
);
85
86
//////////
87
/// Destroy the CrowdMonitor.
88
~
CrowdMonitor
();
89
90
//////////
91
/// Acquire the read-only lock associated with this
92
/// <b>CrowdMonitor</b>. Multiple threads may hold the
93
/// read-only lock simultaneously.
94
void
readLock();
95
96
//////////
97
/// Release the read-only lock obtained from <i>readLock</i>.
98
/// Undefined behavior may result when <i>readUnlock</i> is
99
/// called and a <i>readLock</i> is not held by the calling
100
/// Thread.
101
void
readUnlock();
102
103
//////////
104
/// Acquire the write lock associated with this
105
/// <b>CrowdMonitor</b>. Only one thread may hold the write
106
/// lock, and during the time that this lock is not held, no
107
/// threads may hold the read-only lock.
108
void
writeLock();
109
110
//////////
111
/// Release the write-only lock obtained from <i>writeLock</i>.
112
/// Undefined behavior may result when <i>writeUnlock</i> is
113
/// called and a <i>writeLock</i> is not held by the calling
114
/// Thread.
115
void
writeUnlock();
116
117
private
:
118
const
char
* name_;
119
CrowdMonitor_private
* priv_;
120
121
// Cannot copy them
122
CrowdMonitor
(
const
CrowdMonitor
&);
123
CrowdMonitor
& operator=(
const
CrowdMonitor
&);
124
};
125
}
// End namespace SCIRun
126
127
#endif
128
share.h
SCISHARE
#define SCISHARE
Definition:
share.h:39
name
const char * name[]
Definition:
BoostGraphExampleTests.cc:87
SCIRun::CrowdMonitor
Definition:
CrowdMonitor.h:78
SCIRun::CrowdMonitor_private
Definition:
CrowdMonitor_pthreads.cc:50
Generated on Wed Jul 9 2014 14:31:48 for SCIRun by
1.8.5