File: AA-9-10.html

package info (click to toggle)
ada-reference-manual 20021112web-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, sarge
  • size: 18,652 kB
  • ctags: 8,921
  • sloc: makefile: 52; sh: 20
file content (232 lines) | stat: -rw-r--r-- 17,228 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
    <TITLE>AARM95 - Shared Variables</TITLE>
    <META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
    <META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
    <STYLE type="text/css">
    DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
    TT {font-family: "Courier New", monospace}
    DT {display: compact}
    DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
    DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
    DIV.Index {font-family: "Times New Roman", Times, serif}
    DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
    DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
    DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
    DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
    DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left:  10.0em; margin-bottom: 0.6em}
    DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
    DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
    DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
    DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left:  15.0em; margin-bottom: 0.6em}
    UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
    DD.Hanging {margin-left: 6.0em}
    DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.IndentedHanging {margin-left: 2.0em}
    DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.HangingInBulleted {margin-left: 4.0em}
    DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallHanging {margin-left: 7.5em}
    DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
    DD.SmallIndentedHanging {margin-left: 2.0em}
    DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallHangingInBulleted {margin-left: 5.0em}
    DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.Enumerated {margin-left: 2.0em}
    DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
    DD.SmallEnumerated {margin-left: 2.5em}
    DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
    DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
    </STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-9-9.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-9-11.html">Next</A></P>
<HR>
<H1> 9.10 Shared Variables</H1>

<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;<A NAME="I3831"></A><A NAME="I3832"></A>If two
different objects, including nonoverlapping parts of the same object,
are <I>independently addressable</I>, they can be manipulated concurrently
by two different tasks without synchronization. Normally, any two nonoverlapping
objects are independently addressable. However, if packing, record layout,
or Component_Size is specified for a given composite object, then it
is implementation defined whether or not two nonoverlapping parts of
that composite object are independently addressable. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation defined: </B>Whether
or not two nonoverlapping parts of a composite object are independently
addressable, in the case where packing, record layout, or Component_Size
is specified for the object.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Independent
addressability is the only high level semantic effect of a <FONT FACE="Arial, Helvetica">pragma</FONT>
Pack. If two objects are independently addressable, the implementation
should allocate them in such a way that each can be written by the hardware
without writing the other. For example, unless the user asks for it,
it is generally not feasible to choose a bit-packed representation on
a machine without an atomic bit field insertion instruction, because
there might be tasks that update neighboring subcomponents concurrently,
and locking operations on all subcomponents is generally not a good idea.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Even if packing or one of the
other above-mentioned aspects is specified, subcomponents should still
be updated independently if the hardware efficiently supports it. </FONT></DIV>

<H4 ALIGN=CENTER>Dynamic Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;[Separate tasks
normally proceed independently and concurrently with one another. However,
task interactions can be used to synchronize the actions of two or more
tasks to allow, for example, meaningful communication by the direct updating
and reading of variables shared between the tasks.] The actions of two
different tasks are synchronized in this sense when an action of one
task <I>signals</I> an action of the other task; <A NAME="I3833"></A>an
action A1 is defined to signal an action A2 under the following circumstances:
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 and A2 are part of the execution of the same task,
and the language rules require A1 to be performed before A2;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is the action of an activator that initiates the
activation of a task, and A2 is part of the execution of the task that
is activated;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is part of the activation of a task, and A2 is the
action of waiting for completion of the activation;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is part of the execution of a task, and A2 is the
action of waiting for the termination of the task;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>6.1/1</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>{<I><A HREF="defect1.html#8652/0031">8652/0031</A></I>}
<U>If A1 is the termination of a task T, and A2 is either the evaluation
of the expression T'Terminated or a call to Ada.Task_Identification.Is_Terminated
with an actual parameter that identifies T (see <A HREF="AA-C-7-1.html">C.7.1</A>);</U></LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is the action of issuing an entry call, and A2 is
part of the corresponding execution of the appropriate <FONT FACE="Arial, Helvetica">entry_body</FONT>
or <FONT FACE="Arial, Helvetica">accept_statement</FONT>. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Evaluating
the <FONT FACE="Arial, Helvetica">entry_index</FONT> of an <FONT FACE="Arial, Helvetica">accept_statement</FONT>
is not synchronized with a corresponding entry call, nor is evaluating
the entry barrier of an <FONT FACE="Arial, Helvetica">entry_body</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is part of the execution of an <FONT FACE="Arial, Helvetica">accept_statement</FONT>
or <FONT FACE="Arial, Helvetica">entry_body</FONT>, and A2 is the action
of returning from the corresponding entry call;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If A1 is part of the execution of a protected procedure
body or <FONT FACE="Arial, Helvetica">entry_body</FONT> for a given protected
object, and A2 is part of a later execution of an <FONT FACE="Arial, Helvetica">entry_body</FONT>
for the same protected object; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The underlying
principle here is that for one action to ``signal'' a second, the second
action has to follow a potentially blocking operation, whose blocking
is dependent on the first action in some way. Protected procedures are
not potentially blocking, so they can only be &quot;signalers,&quot;
they cannot be signaled. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Protected
subprogram calls are not defined to signal one another, which means that
such calls alone cannot be used to synchronize access to shared data
outside of a protected object. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The point of this
distinction is so that on multiprocessors with inconsistent caches, the
caches only need to be refreshed at the beginning of an entry body, and
forced out at the end of an entry body or protected procedure that leaves
an entry open. Protected function calls, and protected subprogram calls
for entryless protected objects do not require full cache consistency.
Entryless protected objects are intended to be treated roughly like atomic
objects -- each operation is indivisible with respect to other operations
(unless both are reads), but such operations cannot be used to synchronize
access to other nonvolatile shared variables. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>If A1 signals some action that in turn signals A2. </LI></UL>

<H4 ALIGN=CENTER>Erroneous Execution</H4>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em">&nbsp;&nbsp;&nbsp;&nbsp;<A NAME="I3834"></A>Given
an action of assigning to an object, and an action of reading or updating
a part of the same object (or of a neighboring object if the two are
not independently addressable), then the execution of the actions is
erroneous unless the actions are <I>sequential</I>. <A NAME="I3835"></A>Two
actions are sequential if one of the following is true: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>One action signals the other;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>Both actions occur as part of the execution of the same
task; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Any two actions
of the same task are sequential, even if one does not signal the other
because they can be executed in an ``arbitrary'' (but necessarily equivalent
to some ``sequential'') order. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>Both actions occur as part of protected actions on the
same protected object, and at most one of the actions is part of a call
on a protected function of the protected object. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Because actions
within protected actions do not always imply signaling, we have to mention
them here explicitly to make sure that actions occurring within different
protected actions of the same protected object are sequential with respect
to one another (unless both are part of calls on protected functions).
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>It doesn't
matter whether or not the variable being assigned is actually a subcomponent
of the protected object; globals can be safely updated from within the
bodies of protected procedures or entries. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal">&nbsp;&nbsp;&nbsp;&nbsp;A <FONT FACE="Arial, Helvetica">pragma</FONT>
Atomic or Atomic_Components may also be used to ensure that certain reads
and updates are sequential -- see <A HREF="AA-C-6.html">C.6</A>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>If two actions
are ``sequential'' it is known that their executions don't overlap in
time, but it is not necessarily specified which occurs first. For example,
all actions of a single task are sequential, even though the exact order
of execution is not fully specified for all constructs. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Note that if
two assignments to the same variable are sequential, but neither signals
the other, then the program is not erroneous, but it is not specified
which assignment ultimately prevails. Such a situation usually corresponds
to a programming mistake, but in some (rare) cases, the order makes no
difference, and for this reason this situation is not considered erroneous
nor even a bounded error. In Ada 83, this was considered an ``incorrect
order dependence'' if the ``effect'' of the program was affected, but
``effect'' was never fully defined. In Ada 95, this situation represents
a potential nonportability, and a friendly compiler might want to warn
the programmer about the situation, but it is not considered an error.
An example where this would come up would be in gathering statistics
as part of referencing some information, where the assignments associated
with statistics gathering don't need to be ordered since they are just
accumulating aggregate counts, sums, products, etc. </FONT></DIV>

<HR>
<P><A HREF="AA-TOC.html">Contents</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-0-29.html">Index</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-9-9.html">Previous</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-9-11.html">Next</A>&nbsp;&nbsp;&nbsp;<A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>