Debian Codegraph @

source_2020/09.mss

raw
1 @Part(09, Root="ada.mss")
2
3 @Comment{$Date: 2020/06/03 00:09:00 $}
4 @LabeledSection{Tasks and Synchronization}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/09.mss,v $}
7 @Comment{$Revision: 1.139 $}
8
9 @begin{Intro}
10
11 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
12 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1],ARef=[AI12-0330-1]}
13 @PDefn2{Term=[execution], Sec=(Ada program)}
14 The execution of an Ada program consists of the execution of one
15 or more @i(tasks).
16 @Defn{task}
17 @Defn2{Term=[interaction], Sec=(between tasks)}
18 Each task represents a @Chg{Version=[5],New=[separable activity],Old=[separate
19 thread of control]} that proceeds independently and concurrently
20 between the points where it @i(interacts) with other tasks.
21 @Chg{Version=[5],New=[A single
22 task, when within the context of a parallel construct, can represent
23 multiple @i<logical threads of control> which can proceed in parallel; in
24 other contexts, each task represents one logical thread of
25 control.@defn{logical thread of control}@defn2{Term=[thread],Sec=[logical]}],Old=[The
26 various forms of task interaction are
27 described in this @Chg{Version=[3],New=[clause],Old=[section]}, and include:]}
28 @Defn{synchronization}
29 @IndexSee{Term=[parallel processing],See=(task)}
30 @IndexSee{Term=[concurrent processing],See=(task)}
31 @IndexSeeAlso{Term=[intertask communication],See=(task)}
32 @begin(Honest)
33 The execution of an Ada program consists of the execution
34 of one or more partitions (see @RefSecNum(Program Execution)),
35 each of which in turn consists of the execution of an environment task
36 and zero or more subtasks.
37 @end(Honest)
38
39 @ChgToGlossary{Version=[5],Kind=[Added],Term=<Logical Thread of Control>,
40 Text=<@ChgAdded{Version=[5],Text=[An activity within the execution of a program
41 that can proceed in parallel with other activities of the same task, or of
42 separate tasks.]}>}
43
44 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0119-1]}
45 @ChgAdded{Version=[5],Type=[Leading],Text=[The
46 various forms of task interaction are described in this clause, and include:]}
47
48 @begin(itemize)
49 the activation and termination of a task;
50
51 @Defn{protected object}
52 a call on a protected subprogram of a @i(protected object),
53 providing exclusive read-write access, or concurrent read-only
54 access to shared data;
55
56 a call on an entry, either of another task,
57 allowing for synchronous communication with that task,
58 or of a protected object, allowing for asynchronous
59 communication with one or more other tasks using that same protected
60 object;
61
62 a timed operation, including a simple delay statement,
63 a timed entry call or accept, or a timed asynchronous
64 select statement (see next
65 item);
66
67 an asynchronous transfer of control as part of an asynchronous
68 select statement, where a task
69 stops what it is doing and begins execution at a different
70 point in response to the completion of an entry call or
71 the expiration of a delay;
72
73 an abort statement, allowing one task to cause the
74 termination of another task.
75 @end(itemize)
76
77 In addition, tasks can communicate indirectly by
78 reading and updating (unprotected) shared
79 variables, presuming the access is properly synchronized through
80 some other kind of task interaction.
81
82 @end{Intro}
83
84 @begin{StaticSem}
85 @Defn{task unit}
86 The properties of a task are defined by a corresponding task declaration
87 and @nt<task_body>, which together define a program unit
88 called a @i(task unit).
89 @end{StaticSem}
90
91 @begin{RunTime}
92 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
93 Over time, tasks proceed through various @i(states).
94 @PDefn2{Term=[task state], Sec=(inactive)}
95 @Defn2{Term=[inactive], Sec=(a task state)}
96 @PDefn2{Term=[task state], Sec=(blocked)}
97 @Defn2{Term=[blocked], Sec=(a task state)}
98 @PDefn2{Term=[task state], Sec=(ready)}
99 @Defn2{Term=[ready], Sec=(a task state)}
100 @PDefn2{Term=[task state], Sec=(terminated)}
101 @Defn2{Term=[terminated], Sec=(a task state)}
102 A task is initially @i(inactive); upon activation, and prior to its
103 @i{termination}
104 it is either @i(blocked) (as part
105 of some task interaction) or @i(ready) to run.
106 @Defn2{Term=[execution resource], Sec=(required for a task to run)}
107 While ready, a task competes for the available
108 @i(execution resources) that it requires to run.@Chg{Version=[5],New=[
109 In the context of a parallel construct, a single task can utilize
110 multiple processing resources simultaneously.],Old=[]}
111 @begin(Discussion)
112 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
113 @Defn{task dispatching policy}
114 @Defn{dispatching policy for tasks}
115 The means for selecting which of the ready tasks to run,
116 given the currently available execution resources, is determined by the
117 @i(task dispatching policy) in effect, which is generally
118 implementation defined, but may be controlled by
119 @Chg{Version=[3],New=[aspects, ],Old=[]}pragmas@Chg{Version=[3],New=[, ],Old=[]}
120 and operations defined in the Real-Time Annex
121 (see @RefSecNum(Priority Scheduling) and @RefSecNum(Dynamic Priorities)).
122 @end(Discussion)
123 @end{RunTime}
124
125 @begin{Notes}
126 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
127 Concurrent task execution may be implemented on
128 multicomputers, multiprocessors, or with interleaved execution on a single
129 physical processor. On the other hand, whenever an implementation can
130 determine that the required semantic effects can be achieved when
131 parts of the execution of a
132 @Chg{Version=[5],New=[single logical thread of control],Old=[given task]}
133 are performed by different physical processors acting in
134 parallel, it may choose to perform them in this way.
135
136 @end{Notes}
137
138 @begin{DiffWord83}
139 The introduction has been rewritten.
140
141 We use the term "concurrent" rather than "parallel" when talking
142 about logically independent execution of threads of control.
143 The term "parallel" is reserved for referring to the
144 situation where multiple physical processors run simultaneously.
145 @end{DiffWord83}
146
147 @begin{DiffWord2012}
148 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0119-1]}
149 @ChgAdded{Version=[5],Text=[Rewrote the introduction to emphasize that
150 threads of control can be generated by parallel constructs as well as tasks.]}
151 @end{DiffWord2012}
152
153
154 @LabeledClause{Task Units and Task Objects}
155
156 @begin{Intro}
157 @Defn{task declaration}
158 A task unit is declared by a @i(task declaration), which has
159 a corresponding @nt<task_body>. A task declaration may be
160 a @nt<task_type_declaration>, in which case it declares
161 a named task type; alternatively, it may be a @nt<single_task_declaration>,
162 in which case it defines an anonymous task type, as well as declaring
163 a named task object of that type.
164 @end{Intro}
165
166 @begin{Syntax}
167 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
168 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
169 @Syn{lhs=<task_type_declaration>,rhs="
170 @key{task} @key{type} @Syn2{defining_identifier} [@Syn2{known_discriminant_part}]@Chg{Version=[3],New=<
171 [@Syn2{aspect_specification}]>,Old=[]} [@key{is}@Chg{Version=[2],New=<
172 [@key{new} @Syn2{interface_list} @key{with}]
173 >,Old=<>} @Syn2{task_definition}];"}
174
175 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00399-01]}
176 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
177 @Syn{lhs=<single_task_declaration>,rhs="
178 @key{task} @Syn2{defining_identifier} @Chg{Version=[3],New=<
179 [@Syn2{aspect_specification}]>,Old=[]}[@key{is}@Chg{Version=[2],New=<
180 [@key{new} @Syn2{interface_list} @key{with}]
181 >,Old=<>} @Syn2{task_definition}];"}
182
183
184 @Syn{lhs=<task_definition>,rhs="
185 {@Syn2{task_item}}
186 [ @key{private}
187 {@Syn2{task_item}}]
188 @key{end} [@SynI{task_}@Syn2{identifier}]"}
189
190 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
191 @Syn{lhs=<task_item>,rhs="@Syn2{entry_declaration} | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]}"}
192
193 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
194 @Syn{lhs=<task_body>,rhs="
195 @key{task} @key{body} @Syn2{defining_identifier}@Chg{Version=[3],New=<
196 [@Syn2{aspect_specification}]>,Old=[]} @key{is}
197 @Syn2{declarative_part}
198 @key{begin}
199 @Syn2{handled_sequence_of_statements}
200 @key{end} [@SynI{task_}@Syn2{identifier}];"}
201
202 @begin{SyntaxText}
203 If a @SynI{task_}@nt{identifier} appears at the
204 end of a @nt{task_definition} or @nt{task_body},
205 it shall repeat the @nt{defining_identifier}.
206 @end{SyntaxText}
207 @end{Syntax}
208
209 @begin{Legality}
210 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00345-01]}@ChgNote{This was just moved below}
211 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[requires a completion], Sec=(@nt{task_declaration})}
212 A task declaration requires a completion@redundant[,
213 which shall be a @nt{task_body},]
214 and every @nt{task_body} shall be the completion of some
215 task declaration.]}
216 @begin(Honest)
217 @ChgRef{Version=[2],Kind=[Deleted]}
218 @ChgDeleted{Version=[2],Text=[The completion can be a @nt{pragma} Import,
219 if the implementation supports it.]}
220 @end(Honest)
221 @end{Legality}
222 @begin{NotIso}
223 @ChgAdded{Version=[3],Noparanum=[T],Text=[@Shrink{@i<Paragraph 8 was
224 deleted.>}]}@Comment{This message should be deleted if the paragraphs
225 are ever renumbered.}
226 @end{NotIso}
227
228
229 @begin{StaticSem}
230
231 A @nt<task_definition> defines a task type and its first subtype.
232 @PDefn2{Term=[visible part], Sec=(of a task unit)}
233 The first list of @nt{task_item}s of a @nt{task_@!definition},
234 together with the @nt{known_@!discriminant_@!part}, if any,
235 is called the visible part of the task unit.
236 @Redundant[@PDefn2{Term=[private part], Sec=(of a task unit)}
237 The optional list of @nt{task_item}s after the reserved
238 word @key{private} is called the private part of the task unit.]
239 @begin{TheProof}
240 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
241 Private part is defined in @Chg{Version=[3],New=[Clause],Old=[Section]}
242 @RefSecNum{Visibility Rules}.
243 @end{theproof}
244
245 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0029],ARef=[AI95-00116-01]}
246 @ChgAdded{Version=[1],Text=[For a task declaration without a
247 @nt{task_definition}, a
248 @nt{task_definition} without @nt{task_item}s is assumed.]}
249
250 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01],ARef=[AI95-00399-01],ARef=[AI95-00419-01]}
251 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0042-1]}
252 @ChgAdded{Version=[2],Text=[For a task declaration
253 with an @nt{interface_list}, the task type
254 inherits user-defined primitive subprograms from each progenitor
255 type (see @RefSecNum{Interface Types}), in the same way that a derived type
256 inherits user-defined primitive subprograms from its progenitor types (see
257 @RefSecNum{Derived Types and Classes}). If the first
258 parameter of a primitive inherited subprogram is of the task type or an access
259 parameter designating the task type, and there is an @nt{entry_declaration} for
260 a single entry with the same identifier within the task declaration,
261 whose profile is type conformant with the
262 prefixed view profile of the inherited subprogram, the inherited subprogram is
263 said to be @i{implemented} by the conforming task entry@Chg{Version=[3],
264 New=[ using an implicitly declared nonabstract subprogram which
265 has the same profile as the inherited subprogram and which
266 overrides it@PDefn2{Term=[override],Sec=[when implemented by]}],
267 Old=[]}.@PDefn2{Term=[implemented],
268 Sec=[by a task entry]}@Defn2{Term=[type conformance],Sec=(required)}]}
269 @begin{Ramification}
270 @ChgRef{Version=[2],Kind=[AddedNormal]}
271 @ChgAdded{Version=[2],Text=[The inherited subprograms can only come from an
272 interface given as part of the task declaration.]}
273 @end{Ramification}
274 @begin{Reason}
275 @ChgRef{Version=[3],Kind=[Added],Aref=[AI05-0042-1]}
276 @ChgAdded{Version=[3],Text=[The part about the implicitly declared
277 subprogram is needed so that a subprogram implemented by an entry is
278 considered to be overridden for the purpose of the other rules of the
279 language. Without it, it would for instance be illegal for an abstract
280 subprogram to be implemented by an entry, because the abstract subprogram
281 would not be overridden. The @LegalityTitle below
282 ensure that there is no conflict between the implicit overriding subprogram
283 and a user-defined overriding subprogram.]}
284 @end{Reason}
285 @end{StaticSem}
286
287 @begin{Legality}
288 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}@ChgNote{This was just moved, not changed}
289 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[requires a completion], Sec=(@nt{task_declaration})}
290 A task declaration requires a completion@redundant[,
291 which shall be a @nt{task_body},]
292 and every @nt{task_body} shall be the completion of some
293 task declaration.]}
294 @begin(Honest)
295 @ChgRef{Version=[2],Kind=[AddedNormal]}
296 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
297 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[If],Old=[The completion
298 can be a @nt{pragma} Import, if]} the implementation supports
299 it@Chg{Version=[3],New=[, the task body can be imported
300 (using aspect Import, see @RefSecNum{Interfacing Aspects}),
301 in which case no explicit @nt{task_body} is allowed],Old=[]}.]}
302 @end(Honest)
303
304 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00399-01]}
305 @ChgAdded{Version=[2],Text=[@Redundant[Each @i{interface_}@nt{subtype_mark} of an
306 @nt{interface_list} appearing within a task declaration shall denote
307 a limited interface type that is not a protected interface.]]}
308 @begin(TheProof)
309 @ChgRef{Version=[2],Kind=[AddedNormal]}
310 @ChgAdded{Version=[2],Text=[@RefSecNum{Interface Types} requires that an
311 @nt{interface_list} only name interface types, and limits the descendants of
312 the various kinds of interface types. Only a limited, task, or
313 synchronized interface can have a task type descendant. Nonlimited or
314 protected interfaces are not allowed, as they offer operations that a task
315 does not have.]}
316 @end(TheProof)
317
318 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
319 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0090-1]}
320 @ChgAdded{Version=[2],Text=[The prefixed view profile of an explicitly
321 declared primitive subprogram of a tagged task type shall not be type
322 conformant with any entry of the task type, if the @Chg{Version=[3],New=[
323 subprogram has the same defining name as the entry and the ],Old=[]}first
324 parameter of the subprogram is of the task type or is an
325 access parameter designating the task type.@Defn2{Term=[type conformance],Sec=(required)}]}
326 @begin(Reason)
327 @ChgRef{Version=[2],Kind=[AddedNormal]}
328 @ChgAdded{Version=[2],Text=[This prevents the existence of two operations
329 with the same name and profile which could be called with a prefixed view.
330 If the operation was inherited, this would be illegal by the following rules;
331 this rule puts inherited and noninherited routines on the same footing.
332 Note that this only applies to tagged task types (that is, those with an
333 interface in their declaration); we do that as there is no problem with
334 prefixed view calls of primitive operations for @lquotes@;normal@rquotes
335 task types, and having this rule apply to all tasks would be incompatible
336 with Ada 95.]}
337 @end(Reason)
338
339 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00399-01]}
340 @ChgAdded{Version=[2],Type=[Leading],Text=[For each primitive subprogram
341 inherited by the type declared by a task declaration, at most one of the
342 following shall apply:]}
343
344 @begin{Itemize}
345 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
346 @ChgAdded{Version=[2],Text=[the inherited subprogram is overridden with a
347 primitive subprogram of the task type, in which case the overriding subprogram
348 shall be subtype conformant with the inherited subprogram and not abstract;
349 or@Defn2{Term=[subtype conformance],Sec=(required)}]}
350
351 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01]}
352 @ChgAdded{Version=[2],Text=[the inherited subprogram is implemented by a
353 single entry of the task type; in which case its prefixed view profile
354 shall be subtype conformant with that of the task entry.
355 @Defn2{Term=[subtype conformance],Sec=(required)}]}
356
357 @begin(Ramification)
358 @ChgRef{Version=[2],Kind=[AddedNormal]}
359 @ChgAdded{Version=[2],Text=[An entry may implement two subprograms from the
360 ancestors, one whose first parameter is of type @i<T> and one whose first
361 parameter is of type @key{access} @i{T}. That doesn't cause implementation
362 problems because @lquotes@;implemented by@rquotes (unlike
363 @lquotes@;overridden@rquote) probably entails the creation of wrappers.]}
364 @end(Ramification)
365
366 @end{Itemize}
367
368 @ChgRef{Version=[2],Kind=[Added]}
369 @ChgAdded{Version=[2],Text=[If neither applies, the inherited subprogram shall be a
370 null procedure. @PDefn{generic contract issue}In addition to the places where
371 @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
372 these rules also apply in the private part of an instance of a generic unit.]}
373 @begin{Reason}
374 @ChgRef{Version=[2],Kind=[AddedNormal]}
375 @ChgAdded{Version=[2],Text=[Each inherited subprogram can only have a single
376 implementation (either from overriding a subprogram or implementing an entry),
377 and must have an implementation unless the subprogram is a null procedure.]}
378 @end{Reason}
379
380 @end{Legality}
381
382 @begin{RunTime}
383 @redundant[@PDefn2{Term=[elaboration], Sec=(task declaration)}
384 The elaboration of a task declaration elaborates the @nt<task_definition>.
385 @PDefn2{Term=[elaboration], Sec=(single_task_declaration)}
386 The elaboration of a @nt<single_@!task_@!declaration> also creates
387 an object of an (anonymous) task type.]
388 @begin(TheProof)
389 This is redundant with the general rules for the elaboration
390 of a @nt<full_type_declaration> and an @nt<object_declaration>.
391 @end(TheProof)
392
393 @PDefn2{Term=[elaboration], Sec=(task_definition)}
394 @Redundant[The elaboration of a @nt<task_definition>
395 creates the task type and its first
396 subtype;] it also includes the elaboration of the @nt<entry_declaration>s
397 in the given order.
398
399 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
400 @PDefn2{Term=[initialization], Sec=(of a task object)}
401 As part of the initialization of a task object, any
402 @Chg{New=[@nt<aspect_clause>s],Old=[@nt<representation_clause>s]} and
403 any per-object constraints associated with @nt<entry_@!declaration>s
404 of the corresponding @nt<task_@!definition> are elaborated in the given order.
405 @begin{Reason}
406 @ChgRef{Version=[1],Kind=[Revised]}
407 The only @Chg{New=[@nt<aspect_clause>s],Old=[@nt<representation_clause>s]}
408 defined for task entries are ones that specify the Address of an entry,
409 as part of defining an interrupt entry.
410 These clearly need to be elaborated per-object, not per-type.
411 Normally the address will be a function of a discriminant,
412 if such an Address clause is in a task type rather than a single task
413 declaration, though it could rely on a parameterless function
414 that allocates sequential interrupt vectors.
415
416 We do not mention representation pragmas, since each
417 pragma may have its own elaboration rules.
418 @end{Reason}
419
420 @PDefn2{Term=[elaboration], Sec=(task_body)}
421 The elaboration of a @nt{task_body} has no effect other than to establish
422 that tasks of the type can from then on be activated without
423 failing the Elaboration_Check.
424
425 @redundant[The execution of a @nt<task_body> is invoked by the activation of a
426 task of the corresponding type
427 (see @RefSecNum(Task Execution - Task Activation)).]
428
429 @leading@;The content of a task object of a given task type includes:
430 @begin(itemize)
431 The values of the discriminants of the task object, if any;
432
433 An entry queue for each entry of the task object;
434 @begin(Ramification)
435 "For each entry" implies one queue for each single entry,
436 plus one for each entry of each entry family.
437 @end(Ramification)
438
439 A representation of the state of the associated task.
440 @end(itemize)
441
442 @end{RunTime}
443
444 @begin{Notes}
445
446 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
447 @Chg{Version=[2],New=[Other than
448 in an @nt{access_definition}, the name of a task unit within],Old=[Within]}
449 the declaration or body of @Chg{Version=[2],New=[the],Old=[a]} task
450 unit@Chg{Version=[2],New=[],Old=[, the name of
451 the task unit]} denotes the current instance of the unit
452 (see @RefSecNum(The Context of Overload Resolution)),
453 rather than the first subtype of the corresponding task type (and
454 thus the name cannot be used as a @nt<subtype_mark>).
455 @begin(Discussion)
456 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
457 @Chg{Version=[2],New=[It can be used as a @nt{subtype_mark} in an anonymous
458 access type. In addition],Old=[However]}, it is possible to refer to
459 some other subtype of the task type within its body,
460 presuming such a subtype has been
461 declared between the @nt<task_type_declaration> and the @nt<task_body>.
462 @end(Discussion)
463
464 The notation of a @nt<selected_component> can be used to denote a discriminant
465 of a task (see @RefSecNum(Selected Components)).
466 Within a task unit, the name of a discriminant of the task type
467 denotes the corresponding discriminant of the current instance
468 of the unit.
469
470 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
471 A task type is a limited type (see @RefSecNum(Limited Types)),
472 and hence @Chg{Version=[2],New=[precludes use of @nt{assignment_statement}s and],
473 Old=[has neither an assignment operation nor]} predefined equality operators.
474 If an application needs to store and exchange task identities, it
475 can do so by defining an access type designating the corresponding
476 task objects and by using access values for identification purposes.
477 Assignment is available for such an access type as for any
478 access type.
479 Alternatively, if the implementation supports the
480 Systems Programming Annex,
481 the Identity attribute
482 can be used for task identification
483 (see @Chg{Version=[2],New=[@RefSecNum(The Package Task_Identification)],
484 Old=[@RefSecNum(Task Information)]}).
485 @end{Notes}
486
487 @begin{Examples}
488 @leading@keepnext@i{Examples of declarations of task types:}
489 @begin{Example}
490 @key(task) @key(type) Server @key(is)
491 @key(entry) Next_Work_Item(WI : @key(in) Work_Item);
492 @key(entry) Shut_Down;
493 @key(end) Server;
494
495 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
496 @key(task) @key(type) Keyboard_Driver(ID : Keyboard_ID := New_ID) @key(is)@Chg{Version=[2],New=[
497 @key(new) Serial_Device @key(with) --@RI[ see @RefSecNum{Interface Types}]],Old=[]}
498 @key(entry) Read (C : @key(out) Character);
499 @key(entry) Write(C : @key(in) Character);
500 @key(end) Keyboard_Driver;
501 @end{Example}
502
503 @leading@keepnext@i{Examples of declarations of single tasks:}
504 @begin{Example}
505 @key(task) Controller @key(is)
506 @key(entry) Request(Level)(D : Item); --@RI[ a family of entries]
507 @key(end) Controller;
508
509 @key(task) Parser @key(is)
510 @key(entry) Next_Lexeme(L : @key(in) Lexical_Element);
511 @key(entry) Next_Action(A : @key(out) Parser_Action);
512 @key(end);
513
514 @key(task) User; --@RI[ has no entries]
515 @end{Example}
516
517 @begin{WideAbove}
518 @leading@keepnext@i{Examples of task objects:}
519 @end{WideAbove}
520 @begin{Example}
521 Agent : Server;
522 Teletype : Keyboard_Driver(TTY_ID);
523 Pool : @key(array)(1 .. 10) @key(of) Keyboard_Driver;
524 @end{Example}
525
526 @begin{WideAbove}
527 @leading@keepnext@i{Example of access type designating task objects:}
528 @end{WideAbove}
529 @begin{Example}
530 @key(type) Keyboard @key(is) @key(access) Keyboard_Driver;
531 Terminal : Keyboard := @key(new) Keyboard_Driver(Term_ID);
532 @end{Example}
533
534 @end{Examples}
535
536 @begin{Extend83}
537 @ChgRef{Version=[1],Kind=[Revised]}
538 @Defn{extensions to Ada 83}
539 The syntax rules for task declarations are modified to allow a
540 @nt{known_discriminant_part}, and to allow a private part.
541 They are also modified to allow @nt{entry_declaration}s and
542 @Chg{New=[@nt<aspect_clause>s],Old=[@nt<representation_clause>s]} to be mixed.
543 @end{Extend83}
544
545 @begin{DiffWord83}
546 The syntax rules for tasks have been split up according to task types and
547 single tasks.
548 In particular:
549 The syntax rules for @ntf{task_declaration} and @ntf{task_specification} are
550 removed. The syntax rules for
551 @nt{task_type_declaration}, @nt{single_task_declaration}, @nt{task_definition}
552 and @nt{task_item} are new.
553
554 The syntax rule for @nt{task_body} now uses the nonterminal
555 @nt{handled_sequence_of_statements}.
556
557 The @nt{declarative_part} of a @nt{task_body} is now required;
558 that doesn't make any real difference,
559 because a @nt{declarative_part} can be empty.
560 @end{DiffWord83}
561
562 @begin{Extend95}
563 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00397-01],ARef=[AI95-00399-01],ARef=[AI95-00419-01]}
564 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
565 Task types and single tasks can be derived from one or more interfaces.
566 Entries of the task type can implement the primitive operations of an
567 interface. @nt{Overriding_indicator}s can be used to specify whether or not
568 an entry implements a primitive operation.]}
569 @end{Extend95}
570
571 @begin{DiffWord95}
572 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0029],ARef=[AI95-00116-01]}
573 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that a task type has an
574 implicit empty @nt{task_definition} if none is given.]}
575
576 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
577 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed representation clauses
578 to aspect clauses to reflect that they are used for more than just
579 representation.]}
580
581 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
582 @ChgAdded{Version=[2],Text=[Revised the note on operations of task types to
583 reflect that limited types do have an assignment operation, but not
584 copying (@nt{assignment_statement}s).]}
585
586 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
587 @ChgAdded{Version=[2],Text=[Revised the note on use of the name of
588 a task type within itself to reflect the exception for anonymous
589 access types.]}
590 @end{DiffWord95}
591
592 @begin{Extend2005}
593 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
594 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
595 An optional @nt{aspect_specification} can be used in a
596 @nt{task_type_declaration}, a @nt{single_task_declaration}, and a
597 @nt{task_body}. This is described in @RefSecNum{Aspect Specifications}.]}
598 @end{Extend2005}
599
600 @begin{DiffWord2005}
601 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0042-1]}
602 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that an
603 inherited procedure of a progenitor is overridden when it is
604 implemented by an entry.]}
605
606 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
607 @ChgAdded{Version=[3],Text=[@b<Correction:> Added the missing
608 defining name in the no conflicting primitive operation rule.]}
609 @end{DiffWord2005}
610
611
612 @LabeledClause{Task Execution - Task Activation}
613
614 @begin{RunTime}
615
616 @PDefn2{Term=[execution], Sec=(task)}
617 The execution of a task of a given task type consists of the execution
618 of the corresponding @nt{task_body}.
619 @PDefn2{Term=[execution], Sec=(task_body)}
620 @Defn2{Term=[task], Sec=(execution)}
621 @Defn2{Term=[activation], Sec=(of a task)}
622 @Defn2{Term=[task], Sec=(activation)}
623 The initial part of this execution is called the @i(activation) of
624 the task; it consists of the elaboration of the @nt<declarative_part>
625 of the @nt<task_body>.
626 @Defn{activation failure}
627 Should an exception be propagated by the elaboration
628 of its @nt<declarative_part>,
629 the activation of the task is defined to have @i(failed),
630 and it becomes a completed task.
631
632 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
633 A task object (which represents one task) can be @Chg{Version=[2],New=[a part
634 of a stand-alone object, of an object created by],Old=[created either as
635 part of the elaboration
636 of an @nt<object_@!declaration> occurring immediately within some
637 declarative region, or as part of the evaluation of]}
638 an @nt{allocator}@Chg{Version=[2],New=[, or of an anonymous object of a limited
639 type, or a coextension of one of these],Old=[]}. All
640 tasks@Chg{Version=[2],New=[ that are part or coextensions of any
641 of the stand-alone objects],Old=[]}
642 created by the elaboration of @nt<object_@!declaration>s@Chg{Version=[2],
643 New=[ (or @nt{generic_association}s of formal objects of
644 mode @key{in})],Old=[]}
645 of a single declarative region@Chg{Version=[2],
646 New=[],Old=[ (including subcomponents of the declared objects)]}
647 are activated together.
648 @Chg{Version=[2],New=[All tasks that are part or coextensions of a single
649 object that is not a stand-alone object are activated together.],Old=[Similarly,
650 all tasks created by the evaluation of a single @nt<allocator>
651 are activated together. The activation of a task is associated
652 with the innermost @nt<allocator> or @nt<object_@!declaration>
653 that is responsible for its creation.]}
654 @begin{Discussion}
655 The initialization of an @nt{object_declaration} or @nt{allocator} can
656 indirectly include the creation of other objects that contain tasks.
657 For example, the default expression for a subcomponent of an object
658 created by an @nt{allocator} might call a function that evaluates a
659 completely different @nt{allocator}. Tasks created by the two
660 allocators are @i{not} activated together.
661 @end{Discussion}
662
663 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
664 For @Chg{Version=[2],New=[the ],Old=[]}tasks@Chg{Version=[2],New=[],Old=[
665 created by the elaboration of @nt<object_declaration>s]}
666 of a given declarative region, the activations are initiated
667 within the context of the @nt<handled_@!sequence_of_@!statements>
668 (and its associated @nt<exception_@!handler>s if any @em
669 see @RefSecNum{Exception Handlers}), just prior to executing the
670 statements of the @Chg{Version=[2],New=[@nt{handled_sequence_of_statements}],
671 Old=[@ntf<_sequence>]}.
672 @Redundant[For a package without an explicit body or an explicit
673 @nt<handled_@!sequence_of_@!statements>,
674 an implicit body or an implicit @nt<null_@!statement> is assumed,
675 as defined in @RefSecNum(Package Bodies).]
676 @begin(Ramification)
677 If Tasking_Error is raised, it can be handled by handlers of
678 the @nt<handled_@!sequence_of_@!statements>.
679 @end(Ramification)
680
681 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
682 For tasks @Chg{Version=[2],New=[that are part or coextensions of a single
683 object that is
684 not a stand-alone object, activations are initiated after completing any
685 initialization of the outermost object enclosing these tasks, prior
686 to performing any other operation on the outermost object. In
687 particular, for tasks that are part or coextensions of the object ],
688 Old=[]}created by the evaluation of an @nt<allocator>,
689 the activations are initiated as the last step of
690 evaluating the @nt<allocator>, @Chg{Version=[2],New=[],Old=[after completing
691 any initialization for the object created by the @nt<allocator>,
692 and ]}prior to returning the new access
693 value.@Chg{Version=[2],New=[ For tasks that are part or coextensions of an
694 object that is the result of a function call, the activations are
695 not initiated until after the function returns.],Old=[]}
696
697 @begin{Discussion}
698 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
699 @ChgAdded{Version=[2],Text=[The intent is that @lquotes@;temporary@rquotes@;
700 objects with task parts (or coextensions) are treated similarly to an
701 object created by an
702 allocator. The @lquotes@;whole@rquotes@; object is initialized, and then all
703 of the task parts (including the coextensions) are activated together. Each
704 such @lquotes@;whole@rquotes@;
705 object has its own task activation sequence, involving the activating task
706 being suspended until all the new tasks complete their activation.]}
707 @end{Discussion}
708
709 @IndexCheck{Tasking_Check}
710 @Defn2{Term=[activator], Sec=(of a task)}
711 @PDefn2{term=[blocked], Sec=(waiting for activations to complete)}
712 The task that created the new tasks and initiated their
713 activations (the @i(activator)) is
714 blocked until all of these activations complete (successfully
715 or not).
716 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of runtime check)}
717 Once all of these activations are complete,
718 if the activation
719 of any of the tasks has failed
720 @Redundant[(due to the propagation of an exception)],
721 Tasking_Error is raised in the activator, at the place at which
722 it initiated the activations. Otherwise, the activator
723 proceeds with its execution normally. Any tasks that are aborted
724 prior to completing their activation are ignored when determining
725 whether to raise Tasking_Error.
726 @begin(Ramification)
727 Note that a task created by an @nt<allocator> does not necessarily
728 depend on its activator; in such a case the activator's termination
729 can precede the termination of the newly created task.
730 @end(Ramification)
731 @begin(Discussion)
732 Tasking_Error is raised only once, even if two or more
733 of the tasks being activated fail their activation.
734 @end(Discussion)
735 @begin{Honest}
736 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00265-01]}
737 @ChgAdded{Version=[2],Text=[The pragma Partition_Elaboration_Policy (see
738 @RefSecNum{Pragma Partition_Elaboration_Policy})
739 can be used to defer task activation to a later point, thus changing
740 many of these rules.]}
741 @end{Honest}
742
743 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0045-1]}
744 @Chg{Version=[3],New=[If the master that directly encloses the point where the
745 activation of a task @i<T> would be initiated, completes before the activation
746 of @i<T> is initiated, @i<T> becomes terminated and is never activated.
747 Furthermore, if a return statement is left such that the return object is not
748 returned to the caller, any task that was created as a part of the return
749 object or one of its coextensions immediately becomes],
750 Old=[Should the task that created
751 the new tasks never reach the point
752 where it would initiate the activations (due to an abort or
753 the raising of an exception),
754 the newly created tasks become]}
755 terminated @Chg{Version=[3],New=[and is],Old=[are]}
756 never activated.
757 @begin{Ramification}
758 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0045-1]}
759 @ChgAdded{Version=[3],Text=[The first case can only happen if the activation
760 point of T is not reached due to an exception being raised or a task or
761 statement being aborted. Note that this is exclusive; if the master
762 completes normally and starts finalization, we're already past the
763 activation point.]}
764
765 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0045-1]}
766 @ChgAdded{Version=[3],Text=[The second case can happen with an exception being
767 raised in a return statement, by an exit or goto from an
768 @nt{extended_return_statement}, or by a return statement being aborted. Any
769 tasks created for the return object of such a return statement are never
770 activated.]}
771 @end{Ramification}
772 @end{RunTime}
773
774 @begin{Notes}
775
776 An entry of a task can be called before the task has been activated.
777
778 If several tasks are activated together, the execution of any of these
779 tasks need not await the end of the activation of the other tasks.
780
781 A task can become completed during its activation either because of an
782 exception or because it is aborted
783 (see @RefSecNum(Abort of a Task - Abort of a Sequence of Statements)).
784
785 @end{Notes}
786
787 @begin{Examples}
788 @leading@keepnext@i{Example of task activation:}
789 @begin{Example}
790 @key(procedure) P @key(is)
791 A, B : Server; --@RI[ elaborate the task objects A, B]
792 C : Server; --@RI[ elaborate the task object C]
793 @key(begin)
794 --@RI[ the tasks A, B, C are activated together before the first statement]
795 ...
796 @key(end);
797 @end{Example}
798
799 @end{Examples}
800
801 @begin{DiffWord83}
802
803 We have replaced the term @i{suspended} with @i{blocked},
804 since we didn't want to consider a task blocked when it was
805 simply competing for execution resources. "Suspended" is sometimes
806 used more generally to refer to tasks that are not actually running
807 on some processor, due to the lack of resources.
808
809 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
810 This @Chg{Version=[3],New=[subclause],Old=[clause]} has been rewritten
811 in an attempt to improve presentation.
812 @end{DiffWord83}
813
814 @begin{DiffWord95}
815 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
816 @ChgAdded{Version=[2],Text=[Adjusted the wording for activating tasks to
817 handle the case of anonymous function return objects. This is critical;
818 we don't want to be waiting for the tasks in a return object when we exit
819 the function normally.]}
820 @end{DiffWord95}
821
822 @begin{DiffWord2005}
823 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0045-1]}
824 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording that
825 handles tasks that are never activated to ensure that no lookahead is implied
826 and to make it clear that tasks created by return statements that never
827 return are never activated.]}
828 @end{DiffWord2005}
829
830
831 @LabeledClause{Task Dependence - Termination of Tasks}
832
833 @begin{RunTime}
834
835 @leading@Defn2{Term=[dependence], Sec=(of a task on a master)}
836 @Defn2{Term=[task], Sec=(dependence)}
837 @Defn2{Term=[task], Sec=(completion)}
838 @Defn2{Term=[task], Sec=(termination)}
839 Each task (other than an environment task @em see @RefSecNum(Program Execution))
840 @i(depends) on one or more masters
841 (see @RefSecNum(Completion and Finalization)), as follows:
842 @begin(itemize)
843 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0070-1]}
844 If the task is created by the evaluation of an @nt<allocator>
845 for a given @Chg{Version=[4],New=[named ],Old=[]}access type,
846 it depends on each master that includes the
847 elaboration of the declaration of the ultimate ancestor of the given
848 access type.
849
850 If the task is created by the elaboration of an @nt<object_declaration>,
851 it depends on each master that includes this elaboration.
852
853 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]}
854 @ChgAdded{Version=[2],Text=[Otherwise, the task depends on
855 the master of the outermost object of which it is a part (as determined by the
856 accessibility level of that object @em see
857 @RefSecNum{Operations of Access Types} and
858 @RefSecNum{Completion and Finalization}), as well as on any master whose
859 execution includes that of the master of the outermost object.]}
860 @begin{Ramification}
861 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
862 @ChgAdded{Version=[2],Text=[The master of a task created by a return
863 statement changes when the accessibility of the return object changes. Note
864 that its activation happens, if at all, only after the function returns and
865 all accessibility level changes have occurred.]}
866 @end{Ramification}
867 @end(itemize)
868
869 @Defn2{term=[dependence], Sec=(of a task on another task)}
870 Furthermore, if a task depends on a given master, it is defined
871 to depend on the task that executes the master, and (recursively)
872 on any master of that task.
873 @begin{Discussion}
874 Don't confuse these kinds of dependences with the
875 dependences among compilation units defined in
876 @RefSec{Compilation Units - Library Units}.
877 @end{Discussion}
878
879 A task is said to be @i(completed) when the execution of its corresponding
880 @nt<task_body> is completed. A task is said to be @i(terminated) when
881 any finalization of the @nt<task_body> has been performed
882 (see @RefSecNum(Completion and Finalization)).
883 @Redundant[The first step of finalizing a master
884 (including a @nt<task_body>) is to
885 wait for the termination of any tasks dependent on the master.]
886 @PDefn2{Term=[blocked], Sec=(waiting for dependents to terminate)}
887 The task executing the master is blocked until all the dependents
888 have terminated. @Redundant[Any remaining finalization is then performed
889 and the master is left.]
890
891 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Doubled word}
892 @leading@;Completion of a task (and the corresponding @nt<task_body>) can
893 occur when the task is blocked at a @nt<select_@!statement> with an
894 @Chg{New=[],Old=[an ]}open @nt<terminate_alternative>
895 (see @RefSecNum(Selective Accept)); the open @nt<terminate_alternative>
896 is selected if and only if the following conditions are satisfied:
897 @begin{itemize}
898 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00415-01]}
899 The task depends on some completed master;@Chg{Version=[2],New=[ and],Old=[]}
900
901 Each task that depends on the master considered is either already
902 terminated or similarly blocked at a @nt<select_statement>
903 with an open @nt{terminate_alternative}.
904 @end{itemize}
905
906 When both conditions are satisfied, the task considered becomes
907 completed, together with all tasks that depend on the master
908 considered that are not yet completed.
909 @begin(Ramification)
910 Any required finalization is performed after the selection
911 of @nt<terminate_alternative>s. The tasks are not callable
912 during the finalization. In some ways it is as though they were
913 aborted.
914 @end(Ramification)
915
916 @end{RunTime}
917
918 @begin{Notes}
919
920 The full view of a limited private type can be a task type, or
921 can have subcomponents of a task type. Creation of an object of
922 such a type creates dependences according to the full type.
923
924 An @nt<object_renaming_declaration> defines a new view of an
925 existing entity and hence creates no further dependence.
926
927 The rules given for the collective completion of a group
928 of tasks all blocked on @nt<select_statement>s with
929 open @nt<terminate_alternative>s ensure that the collective
930 completion can occur only when there are no remaining active
931 tasks that could call one of the tasks being collectively completed.
932
933 If two or more tasks are blocked on @nt<select_statement>s
934 with open @nt{terminate_alternative}s, and become
935 completed collectively, their finalization actions proceed concurrently.
936
937 @leading@keepnext@;The completion of a task can occur due to any of the following:
938 @begin{itemize}
939 the raising of an exception during the elaboration of the
940 @nt{declarative_part} of the corresponding @nt{task_body};
941
942 the completion of the
943 @nt{handled_sequence_of_statements} of the corresponding
944 @nt{task_body};
945
946 the selection of
947 an open @nt<terminate_alternative> of a @nt<select_statement>
948 in the corresponding @nt<task_body>;
949
950 the abort of the task.
951 @end{itemize}
952
953 @end{Notes}
954
955 @begin{Examples}
956 @leading@keepnext@i{Example of task dependence:}
957 @begin{Example}
958 @key(declare)
959 @key(type) Global @key(is) @key(access) Server; --@RI[ see @RefSecNum(Task Units and Task Objects)]
960 A, B : Server;
961 G : Global;@Softpage
962 @key(begin)
963 --@RI[ activation of A and B]
964 @key(declare)
965 @key(type) Local @key(is) @key(access) Server;
966 X : Global := @key(new) Server; --@RI[ activation of X.@key{all}]
967 L : Local := @key(new) Server; --@RI[ activation of L.@key{all}]
968 C : Server;@Softpage
969 @key(begin)
970 --@RI[ activation of C]
971 G := X; --@RI[ both G and X designate the same task object]
972 ...
973 @key(end;) --@RI[ await termination of C and L.@key{all} (but not X.@key{all})]
974 ...
975 @key(end;) --@RI[ await termination of A, B, and G.@key{all}]
976 @end{Example}
977
978 @end{Examples}
979
980 @begin{DiffWord83}
981 We have revised the wording to be consistent with the definition
982 of master now given in @RefSec(Completion and Finalization).
983
984 Tasks that used to depend on library packages in Ada 83, now depend on the
985 (implicit) @nt<task_body> of the
986 environment task (see @RefSecNum(Program Execution)).
987 Therefore, the environment task has to wait for
988 them before performing library level finalization and terminating
989 the partition.
990 In Ada 83 the requirement to wait for tasks that depended
991 on library packages was not as clear.
992
993 What was "collective termination" is now "collective completion"
994 resulting from selecting @nt<terminate_alternative>s. This is because
995 finalization still occurs for such tasks, and this happens after
996 selecting the @nt<terminate_alternative>, but before termination.
997 @end{DiffWord83}
998
999 @begin{DiffWord95}
1000 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1001 @ChgAdded{Version=[2],Text=[Added missing wording that explained the
1002 master of tasks that are neither @nt{object_declaration}s nor @nt{allocator}s,
1003 such as function returns.]}
1004 @end{DiffWord95}
1005
1006 @begin{DiffWord2012}
1007 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0070-1]}
1008 @ChgAdded{Version=[4],Text=[@B<Corrigendum:> Ensured that the master of
1009 tasks that are not @nt{allocator}s of named access types is correctly
1010 determined. (Ignoring the accessibility rules of
1011 @RefSecNum{Operations of Access Types} could not be intended.)]}
1012 @end{DiffWord2012}
1013
1014
1015 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
1016 @LabeledClause{Protected Units and Protected Objects}
1017
1018 @begin{Intro}
1019 @Defn{protected object}
1020 @Defn{protected operation}
1021 @Defn{protected subprogram}
1022 @Defn{protected entry}
1023 A @i(protected object) provides coordinated access to shared data,
1024 through calls on its visible @i(protected operations),
1025 which can be @i{protected subprograms} or @i{protected entries}.
1026 @Defn{protected declaration}
1027 @Defn{protected unit}
1028 @Defn{protected declaration}
1029 A @i{protected unit} is declared by a @i(protected declaration), which has
1030 a corresponding @nt<protected_body>.
1031 A protected declaration may be a @nt<protected_type_declaration>,
1032 in which case it declares
1033 a named protected type; alternatively,
1034 it may be a @nt<single_protected_declaration>,
1035 in which case it defines an anonymous protected type, as well as declaring
1036 a named protected object of that type.
1037 @IndexSee{Term=[broadcast signal],See=(protected object)}
1038 @end{Intro}
1039
1040 @begin{Syntax}
1041 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
1042 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
1043 @Syn{lhs=<protected_type_declaration>,rhs="
1044 @key{protected} @key{type} @Syn2{defining_identifier} [@Syn2{known_discriminant_part}]@Chg{Version=[3],New=<
1045 [@Syn2{aspect_specification}]>,Old=[]} @key{is}@Chg{Version=[2],New=<
1046 [@key{new} @Syn2{interface_list} @key{with}]
1047 >,Old=<>} @Syn2{protected_definition};"}
1048
1049
1050 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00399-01]}
1051 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
1052 @Syn{lhs=<single_protected_declaration>,rhs="
1053 @key{protected} @Syn2{defining_identifier}@Chg{Version=[3],New=<
1054 [@Syn2{aspect_specification}]>,Old=[]} @key{is}@Chg{Version=[2],New=<
1055 [@key{new} @Syn2{interface_list} @key{with}]
1056 >,Old=<>} @Syn2{protected_definition};"}
1057
1058
1059 @Syn{lhs=<protected_definition>,rhs="
1060 { @Syn2{protected_operation_declaration} }
1061 [ @key{private}
1062 { @Syn2{protected_element_declaration} } ]
1063 @key{end} [@SynI{protected_}@Syn2{identifier}]"}
1064
1065 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1066 @Syn{lhs=<protected_operation_declaration>,
1067 rhs="@Syn2{subprogram_declaration}
1068 | @Syn2{entry_declaration}
1069 | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]}"}
1070 @Syn{lhs=<protected_element_declaration>,
1071 rhs="@Syn2<protected_operation_declaration>
1072 | @Syn2<component_declaration>"}
1073 @begin{Reason}
1074 We allow the operations and components to be mixed because that's how
1075 other things work (for example, package
1076 declarations). We have relaxed the
1077 ordering rules for the items inside @nt{declarative_part}s and
1078 @nt{task_definition}s as well.
1079 @end{Reason}
1080
1081
1082 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0267-1]}
1083 @Syn{lhs=<protected_body>,rhs="
1084 @key{protected} @key{body} @Syn2{defining_identifier}@Chg{Version=[3],New=<
1085 [@Syn2{aspect_specification}]>,Old=[]} @key{is}
1086 { @Syn2{protected_operation_item} }
1087 @key{end} [@SynI{protected_}@Syn2{identifier}];"}
1088
1089 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0009],ARef=[AI95-00137-01]}
1090 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0147-1]}
1091 @Syn{lhs=<protected_operation_item>,
1092 rhs="@Syn2{subprogram_declaration}
1093 | @Syn2{subprogram_body}
1094 | @Chg{Version=[4],New=[@Syn2{null_procedure_declaration}
1095 | @Syn2{expression_function_declaration}
1096 | ],Old=[]}@Syn2{entry_body}
1097 | @Chg{New=[@Syn2{aspect_clause}],Old=[@Syn2{representation_clause}]}"}
1098
1099 @begin{SyntaxText}
1100 If a @SynI{protected_}@nt{identifier} appears at
1101 the end of a @nt{protected_definition} or @nt{protected_body},
1102 it shall repeat the @nt{defining_identifier}.
1103 @end{SyntaxText}
1104 @end{Syntax}
1105
1106 @begin{Legality}
1107 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00345-01]}@ChgNote{This was just moved below}
1108 @ChgDeleted{Version=[2],Text=[@PDefn2{Term=[requires a completion], Sec=(@nt{protected_declaration})}
1109 A protected declaration requires a completion@redundant[,
1110 which shall be a @nt{protected_@!body},]
1111 and every @nt{protected_@!body} shall be the completion of some
1112 protected declaration.]}
1113 @begin(Honest)
1114 @ChgRef{Version=[2],Kind=[Deleted]}
1115 @ChgDeleted{Version=[2],Text=[The completion can be a @nt{pragma} Import,
1116 if the implementation supports it.]}
1117 @end(Honest)
1118 @end{Legality}
1119 @begin{NotIso}
1120 @ChgAdded{Version=[3],Noparanum=[T],Text=[@Shrink{@i<Paragraph 10 was
1121 deleted.>}]}@Comment{This message should be deleted if the paragraphs
1122 are ever renumbered.}
1123 @end{NotIso}
1124
1125 @begin{StaticSem}
1126
1127 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01],ARef=[AI95-00401-01]}@Comment{This
1128 is no change here, but both of these AIs reference this paragraph, adding and removing text.}
1129 A @nt<protected_definition> defines a protected type and its first subtype.
1130 @PDefn2{Term=[visible part], Sec=(of a protected unit)}
1131 The list of @nt{protected_@!operation_@!declaration}s of a
1132 @nt{protected_@!definition},
1133 together with the @nt{known_@!discriminant_@!part}, if any,
1134 is called the visible part of the protected unit.
1135 @Redundant[@PDefn2{Term=[private part], Sec=(of a protected unit)}
1136 The optional list of @nt{protected_@!element_@!declaration}s after the reserved
1137 word @key{private} is called the private part of the protected
1138 unit.]
1139 @begin{TheProof}
1140 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1141 Private part is defined in @Chg{Version=[3],New=[Clause],Old=[Section]}
1142 @RefSecNum{Visibility Rules}.
1143 @end{theproof}
1144
1145 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01],ARef=[AI95-00399-01],ARef=[AI95-00419-01]}
1146 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0042-1]}
1147 @ChgAdded{Version=[2],Text=[For a protected declaration
1148 with an @nt{interface_list}, the protected type inherits user-defined primitive
1149 subprograms from each progenitor type (see @RefSecNum{Interface Types}), in the
1150 same way that a derived type inherits user-defined primitive subprograms from
1151 its progenitor types (see @RefSecNum{Derived Types and Classes}). If the first
1152 parameter of a primitive inherited subprogram is of the protected type or an
1153 access parameter designating the protected type, and there is a
1154 @nt{protected_operation_declaration} for a protected subprogram or single entry
1155 with the same identifier within the protected declaration, whose
1156 profile is type conformant with the prefixed view profile of the
1157 inherited subprogram, the inherited subprogram is said to be
1158 @i{implemented} by the conforming protected subprogram or
1159 entry@Chg{Version=[3],New=[ using an implicitly declared nonabstract
1160 subprogram which has the same profile as the inherited subprogram and which
1161 overrides it@PDefn2{Term=[override],Sec=[when implemented by]}],
1162 Old=[]}.@PDefn2{Term=[implemented],
1163 Sec=[by a protected subprogram]}@PDefn2{Term=[implemented],
1164 Sec=[by a protected entry]}
1165 @Defn2{Term=[type conformance],Sec=(required)}]}
1166
1167 @begin{Ramification}
1168 @ChgRef{Version=[2],Kind=[AddedNormal]}
1169 @ChgAdded{Version=[2],Text=[The inherited subprograms can only come from an
1170 interface given as part of the protected declaration.]}
1171 @end{Ramification}
1172 @begin{Reason}
1173 @ChgRef{Version=[3],Kind=[Added],Aref=[AI05-0042-1]}
1174 @ChgAdded{Version=[3],Text=[The part about the implicitly declared
1175 subprogram is needed so that a subprogram implemented by an entry or
1176 subprogram is considered to be overridden for the purpose of the
1177 other rules of the language. Without it, it would for instance be illegal
1178 for an abstract subprogram to be implemented by an entry, because the
1179 abstract subprogram would not be overridden. The @LegalityTitle below
1180 ensure that there is no conflict between the implicit overriding subprogram
1181 and a user-defined overriding subprogram.]}
1182 @end{Reason}
1183
1184 @end{StaticSem}
1185
1186 @begin{Legality}
1187 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}@ChgNote{This was just moved, not changed}
1188 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[requires a completion], Sec=(@nt{protected_declaration})}
1189 A protected declaration requires a completion@redundant[,
1190 which shall be a @nt{protected_@!body},]
1191 and every @nt{protected_@!body} shall be the completion of some
1192 protected declaration.]}
1193 @begin(Honest)
1194 @ChgRef{Version=[2],Kind=[AddedNormal]}
1195 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1196 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[If],Old=[The completion
1197 can be a @nt{pragma} Import, if]} the implementation supports
1198 it@Chg{Version=[3],New=[, the protected body can be imported
1199 (using aspect Import, see @RefSecNum{Interfacing Aspects}),
1200 in which case no explicit @nt{protected_body} is allowed],Old=[]}.]}
1201 @end(Honest)
1202
1203 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00399-01]}
1204 @ChgAdded{Version=[2],Text=[@Redundant[Each @i{interface_}@nt{subtype_mark} of an
1205 @nt{interface_list} appearing within a protected declaration shall denote a
1206 limited interface type that is not a task interface.]]}
1207 @begin(TheProof)
1208 @ChgRef{Version=[2],Kind=[AddedNormal]}
1209 @ChgAdded{Version=[2],Text=[@RefSecNum{Interface Types} requires that an
1210 @nt{interface_list} only name interface types, and limits the descendants of
1211 the various kinds of interface types. Only a limited, protected, or
1212 synchronized interface can have a protected type descendant. Nonlimited or
1213 task interfaces are not allowed, as they offer operations that a protected
1214 type does not have.]}
1215 @end(TheProof)
1216
1217 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
1218 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0042-1]}
1219 @ChgAdded{Version=[2],Text=[The prefixed view profile of an explicitly declared
1220 primitive subprogram of a tagged protected type shall not be type conformant
1221 with any protected operation of the protected type, if the@Chg{Version=[3],New=[
1222 subprogram has the same defining name as the protected operation and
1223 the],Old=[]} first parameter of
1224 the subprogram is of the protected type or is an access parameter designating
1225 the protected type.@Defn2{Term=[type conformance],Sec=(required)}]}
1226 @begin(Reason)
1227 @ChgRef{Version=[2],Kind=[AddedNormal]}
1228 @ChgAdded{Version=[2],Text=[This prevents the existence of two operations
1229 with the same name and profile which could be called with a prefixed view.
1230 If the operation was inherited, this would be illegal by the following rules;
1231 this rule puts inherited and noninherited routines on the same footing.
1232 Note that this only applies to tagged protected types (that is, those with an
1233 interface in their declaration); we do that as there is no problem with
1234 prefixed view calls of primitive operations for @lquotes@;normal@rquotes
1235 protected types, and having this rule apply to all protected types would be
1236 incompatible with Ada 95.]}
1237 @end(Reason)
1238
1239
1240
1241 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00399-01]}
1242 @ChgAdded{Version=[2],Type=[Leading],Text=[For each primitive subprogram
1243 inherited by the type declared by a protected declaration, at most one of the
1244 following shall apply:]}
1245
1246 @begin{Itemize}
1247 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1248 @ChgAdded{Version=[2],Text=[the inherited subprogram is overridden with a
1249 primitive subprogram of the protected type, in which case the overriding
1250 subprogram shall be subtype conformant with the inherited
1251 subprogram and not abstract; or@Defn2{Term=[subtype conformance],Sec=(required)}]}
1252
1253
1254 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01]}
1255 @ChgAdded{Version=[2],Text=[the inherited subprogram is implemented by a
1256 protected subprogram or single entry of the protected type,
1257 in which case its prefixed view profile shall be subtype conformant with that
1258 of the protected subprogram or entry.
1259 @Defn2{Term=[subtype conformance],Sec=(required)}]}
1260
1261 @end{Itemize}
1262
1263 @ChgRef{Version=[2],Kind=[Added]}
1264 @ChgAdded{Version=[2],Text=[If neither applies, the inherited subprogram shall
1265 be a null procedure. @PDefn{generic contract issue}In addition to the places
1266 where @LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}),
1267 these rules also apply in the private part of an instance of a generic unit.]}
1268 @begin{Reason}
1269 @ChgRef{Version=[2],Kind=[AddedNormal]}
1270 @ChgAdded{Version=[2],Text=[Each inherited subprogram can only have a single
1271 implementation (either from overriding a subprogram, implementing a
1272 subprogram, or implementing an entry), and must have an implementation unless
1273 the subprogram is a null procedure.]}
1274 @end{Reason}
1275
1276 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1277 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0291-1]}
1278 @ChgAdded{Version=[2],Text=[If an inherited subprogram is implemented by a
1279 protected procedure or an entry, then the first parameter of the inherited
1280 subprogram shall be of mode @key{out} or @key{in out}, or an
1281 access-to-variable parameter.@Chg{Version=[3],New=[
1282 If an inherited subprogram is implemented by a protected function, then the
1283 first parameter of the inherited subprogram shall be of mode @key{in}, but not
1284 an access-to-variable parameter.],Old=[]}]}
1285 @begin{Reason}
1286 @ChgRef{Version=[2],Kind=[AddedNormal]}
1287 @ChgRef{Version=[3],Kind=[Revised]}
1288 @ChgAdded{Version=[2],Text=[For a protected procedure or entry, the protected
1289 object can be read or written (see
1290 @RefSecNum{Protected Subprograms and Protected Actions}). A subprogram
1291 that is implemented by a protected procedure or entry must have a profile
1292 which reflects that in order to avoid confusion.@Chg{Version=[3],New=[
1293 Similarly, a protected function has a parameter that is a constant,
1294 and the inherited routine should reflect that.],Old=[]}]}
1295 @end{Reason}
1296
1297 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
1298 @ChgAdded{Version=[2],Type=[Leading],Text=[If a protected subprogram
1299 declaration has an @nt{overriding_indicator}, then at the point of the
1300 declaration:]}
1301
1302 @begin{Itemize}
1303 @ChgRef{Version=[2],Kind=[Added]}
1304 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1305 @key{overriding}, then the subprogram shall
1306 implement an inherited subprogram;]}
1307
1308 @ChgRef{Version=[2],Kind=[Added]}
1309 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1310 @key{not overriding}, then the subprogram shall
1311 not implement any inherited subprogram.]}
1312
1313 @end{Itemize}
1314
1315 @ChgRef{Version=[2],Kind=[Added]}
1316 @ChgAdded{Version=[2],Text=[@PDefn{generic contract issue}In addition to the
1317 places where @LegalityTitle normally apply (see
1318 @RefSecNum{Generic Instantiation}), these rules also apply in the private part
1319 of an instance of a generic unit.]}
1320
1321 @begin{Discussion}
1322 @ChgRef{Version=[2],Kind=[AddedNormal]}
1323 @ChgAdded{Version=[2],Text=[These rules are subtly different than those for
1324 subprograms (see @RefSecNum{Overriding Indicators}) because there cannot be
1325 @lquotes@;late@rquotes inheritance of primitives from interfaces. Hidden
1326 (that is, private) interfaces are prohibited explicitly (see
1327 @RefSecNum{Private Types and Private Extensions}), as are hidden primitive
1328 operations (as private operations of public abstract types are prohibited
1329 @em see @RefSecNum{Abstract Types and Subprograms}).]}
1330 @end{Discussion}
1331
1332 @end{Legality}
1333
1334 @begin{RunTime}
1335 @redundant[@PDefn2{Term=[elaboration], Sec=(protected declaration)}The
1336 elaboration of a protected declaration
1337 elaborates the @nt<protected_definition>.
1338 @PDefn2{Term=[elaboration], Sec=(single_protected_declaration)}
1339 The elaboration of a @nt<single_@!protected_@!declaration> also creates
1340 an object of an (anonymous) protected type.]
1341 @begin(TheProof)
1342 This is redundant with the general rules for the elaboration
1343 of a @nt<full_type_declaration> and an @nt<object_declaration>.
1344 @end(TheProof)
1345
1346 @PDefn2{Term=[elaboration], Sec=(protected_definition)}
1347 @Redundant[The elaboration of a @nt<protected_definition>
1348 creates the protected type and its first
1349 subtype;] it also includes the elaboration of the
1350 @nt<component_declaration>s and @nt<protected_operation_declaration>s
1351 in the given order.
1352
1353 @redundant[@PDefn2{Term=[initialization], Sec=(of a protected object)}As
1354 part of the initialization of a protected object,
1355 any per-object constraints (see @RefSecNum{Record Types}) are elaborated.]
1356 @begin{Discussion}
1357 We do not mention pragmas since each pragma has its
1358 own elaboration rules.
1359 @end{Discussion}
1360
1361 @PDefn2{Term=[elaboration], Sec=(protected_body)}
1362 The elaboration of a @nt{protected_body} has no other effect than to establish
1363 that protected operations of the type can from then on be called without
1364 failing the Elaboration_Check.
1365
1366 @leading@keepnext@;The content of an object of a given protected type includes:
1367 @begin(itemize)
1368 The values of the components of the
1369 protected object, including (implicitly)
1370 an entry queue for each entry declared for the protected object;
1371 @begin(Ramification)
1372 "For each entry" implies one queue for each single entry,
1373 plus one for each entry of each entry family.
1374 @end(Ramification)
1375
1376 @PDefn2{Term=[execution resource], Sec=(associated with a protected object)}
1377 A representation of the state of the execution resource
1378 @i(associated) with the protected object
1379 (one such resource is associated with each protected object).
1380 @end(itemize)
1381
1382 @Redundant[The execution resource associated with a protected object
1383 has to be acquired to
1384 read or update any components of the protected object;
1385 it can be acquired (as part of a protected action @em
1386 see @RefSecNum(Protected Subprograms and Protected Actions))
1387 either for concurrent read-only access, or for exclusive
1388 read-write access.]
1389
1390 @PDefn2{Term=[finalization], Sec=(of a protected object)}
1391 @Defn2{Term=[Program_Error],Sec=(raised by finalization of a protected object)}
1392 As the first step of the @i{finalization} of a protected object,
1393 each call remaining on any entry queue of the object
1394 is removed from its queue and
1395 Program_Error is raised at the place of the corresponding
1396 @nt<entry_@!call_@!statement>.
1397 @begin(Reason)
1398 @leading@;This is analogous to the raising of Tasking_Error in callers
1399 of a task that completes before accepting the calls.
1400 This situation can only occur due to a
1401 requeue (ignoring premature unchecked_deallocation), since any task that
1402 has accessibility to a protected object is awaited before finalizing
1403 the protected object.
1404 For example:
1405 @begin{Example}
1406 @key[procedure] Main @key[is]
1407 @key[task] T @key[is]
1408 @key[entry] E;
1409 @key[end] T;
1410
1411 @key[task] @key[body] T @key[is]
1412 @key[protected] PO @key[is]
1413 @key[entry] Ee;
1414 @key[end] PO;
1415
1416 @key[protected] @key[body] PO @key[is]
1417 @key[entry] Ee @key[when] False @key[is]
1418 @key[begin]
1419 @key[null];
1420 @key[end] Ee;
1421 @key[end] PO;
1422 @key[begin]
1423 @key[accept] E @key[do]
1424 @key[requeue] PO.Ee;
1425 @key[end] E;
1426 @key[end] T;
1427 @key[begin]
1428 T.E;
1429 @key[end] Main;
1430 @end{Example}
1431
1432 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
1433 The environment task is queued on PO.@Chg{Version=[3],New=[Ee],Old=[EE]}
1434 when PO is finalized.
1435
1436 In a real example, a server task might park callers on a local protected
1437 object for some useful purpose, so we didn't want to disallow this case.
1438 @end(Reason)
1439 @end{RunTime}
1440
1441 @begin{Bounded}
1442 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280-01]}
1443 @ChgAdded{Version=[2],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
1444 It is a bounded error to call an entry or subprogram of a
1445 protected object after that object is finalized. If the error is detected,
1446 Program_Error is raised. Otherwise, the call proceeds normally, which may leave
1447 a task queued forever.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}]}
1448 @begin{Reason}
1449 @ChgRef{Version=[2],Kind=[AddedNormal]}
1450 @ChgAdded{Version=[2],Text=[This is very similar to the finalization rule. It
1451 is a bounded error so that an implementation can avoid the overhead of the
1452 check if it can ensure that the call still will operate properly. Such an
1453 implementation cannot need to return resources (such as locks) to an
1454 executive that it needs to execute calls.]}
1455
1456 @ChgRef{Version=[2],Kind=[AddedNormal]}
1457 @ChgAdded{Version=[2],Type=[Leading],Text=[This case can happen (and has
1458 happened in
1459 production code) when a protected object is accessed from the Finalize routine
1460 of a type. For example:]}
1461 @begin{Example}
1462 @ChgRef{Version=[2],Kind=[AddedNormal]}
1463 @ChgAdded{Version=[2],Text=[@key{with} Ada.Finalization.Controlled;
1464 @key{package} Window_Manager @key{is}
1465 ...
1466 @key{type} Root_Window @key{is new} Ada.Finalization.Controlled @key{with private};
1467 @key{type} Any_Window @key{is access all} Root_Window;
1468 ...
1469 @key{private}
1470 ...
1471 @key{procedure} Finalize (Object : @key{in out} Root_Window);
1472 ...
1473 @key{end} Window_Manager;]}
1474
1475 @ChgRef{Version=[2],Kind=[AddedNormal]}
1476 @ChgAdded{Version=[2],Text=[@key{package body} Window_Manager @key{is}
1477 @key{protected type} Lock @key{is}
1478 @key{entry} Get_Lock;
1479 @key{procedure} Free_Lock;
1480 ...
1481 @key{end} Lock;]}
1482
1483 @ChgRef{Version=[2],Kind=[AddedNormal]}
1484 @ChgAdded{Version=[2],Text=[ Window_Lock : Lock;]}
1485
1486 @ChgRef{Version=[2],Kind=[AddedNormal]}
1487 @ChgAdded{Version=[2],Text=[ @key{procedure} Finalize (Object : @key{in out} Root_Window) @key{is}
1488 @key{begin}
1489 Window_Lock.Get_Lock;
1490 ...
1491 Window_Lock.Free_Lock;
1492 @key{end} Finalize;
1493 ...
1494 A_Window : Any_Window := @key{new} Root_Window;
1495 @key{end} Window_Manager;]}
1496 @end{Example}
1497
1498 @ChgRef{Version=[2],Kind=[AddedNormal]}
1499 @ChgAdded{Version=[2],Text=[The environment task will call Window_Lock for
1500 the object allocated for A_Window when the collection for Any_Window
1501 is finalized, which
1502 will happen after the finalization of Window_Lock (because finalization of the
1503 package body will occur before that of the package specification).]}
1504 @end{Reason}
1505 @end{Bounded}
1506
1507 @begin{Notes}
1508
1509 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
1510 Within the declaration or body of a protected unit@Chg{Version=[2],New=[ other
1511 than in an @nt{access_definition}],Old=[]}, the name of
1512 the protected unit denotes the current instance of the unit
1513 (see @RefSecNum(The Context of Overload Resolution)),
1514 rather than the first subtype of the corresponding protected type (and
1515 thus the name cannot be used as a @nt<subtype_mark>).
1516 @begin(Discussion)
1517 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
1518 @Chg{Version=[2],New=[It can be used as a @nt{subtype_mark} in an anonymous
1519 access type. In addition],Old=[However]}, it is possible to refer to
1520 some other subtype of the protected type within its body,
1521 presuming such a subtype has been
1522 declared between the @nt<protected_type_declaration>
1523 and the @nt<protected_body>.
1524 @end(Discussion)
1525
1526 A @nt<selected_component> can be used to denote a discriminant
1527 of a protected object (see @RefSecNum(Selected Components)).
1528 Within a protected unit, the name of a discriminant of the protected type
1529 denotes the corresponding discriminant of the current instance
1530 of the unit.
1531
1532 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1533 A protected type is a limited type (see @RefSecNum(Limited Types)),
1534 and hence @Chg{Version=[2],New=[precludes use of @nt{assignment_statement}s and],
1535 Old=[has neither an assignment operation nor]} predefined equality operators.
1536
1537 The bodies of the protected operations given in the @nt<protected_body>
1538 define the actions that take place upon calls to the protected operations.
1539
1540 The declarations in the private part are only
1541 visible within the private part and the body of the
1542 protected unit.
1543 @begin{Reason}
1544 @nt{Component_declaration}s are disallowed in a @nt{protected_body}
1545 because, for efficiency, we wish to allow the compiler to
1546 determine the size of protected objects (when not dynamic);
1547 the compiler cannot necessarily see the body.
1548 Furthermore, the semantics of initialization of such objects would be
1549 problematic @em we do not wish to give protected objects complex
1550 initialization semantics similar to task activation.
1551
1552 The same applies to @nt{entry_declaration}s,
1553 since an entry involves an implicit component @em the entry queue.
1554 @end{Reason}
1555
1556 @end{Notes}
1557
1558 @begin{Examples}
1559 @leading@keepnext@i{Example of declaration of protected type and corresponding body:}
1560 @begin{Example}
1561 @key(protected) @key(type) Resource @key(is)
1562 @key(entry) Seize;
1563 @key(procedure) Release;
1564 @key(private)
1565 Busy : Boolean := False;
1566 @key(end) Resource;
1567
1568 @key(protected) @key(body) Resource @key(is)
1569 @key(entry) Seize @key(when not) Busy @key(is)
1570 @key(begin)
1571 Busy := True;
1572 @key(end) Seize;
1573
1574 @key(procedure) Release @key(is)
1575 @key(begin)
1576 Busy := False;
1577 @key(end) Release;
1578 @key(end) Resource;
1579 @end{Example}
1580
1581 @begin{WideAbove}
1582 @leading@keepnext@i{Example of a single protected declaration and corresponding body:}
1583 @end{WideAbove}
1584 @begin{Example}
1585 @key(protected) Shared_Array @key(is)
1586 --@RI[ Index, Item, and Item_Array are global types]
1587 @key(function) Component (N : @key(in) Index) return Item;
1588 @key(procedure) Set_Component(N : @key(in) Index; E : @key(in) Item);
1589 @key(private)
1590 Table : Item_Array(Index) := (others => Null_Item);
1591 @key(end) Shared_Array;
1592
1593 @key(protected) @key(body) Shared_Array @key(is)
1594 @key(function) Component(N : @key(in) Index) @key(return) Item @key(is)
1595 @key(begin)
1596 @key(return) Table(N);
1597 @key(end) Component;
1598
1599 @key(procedure) Set_Component(N : @key(in) Index; E : @key(in) Item) @key(is)
1600 @key(begin)
1601 Table(N) := E;
1602 @key(end) Set_Component;
1603 @key(end) Shared_Array;
1604 @end{Example}
1605
1606 @begin{WideAbove}
1607 @leading@keepnext@i{Examples of protected objects:}
1608 @end{WideAbove}
1609 @begin{Example}
1610 Control : Resource;
1611 Flags : @key(array)(1 .. 100) @key(of) Resource;
1612 @end{Example}
1613 @end{Examples}
1614
1615 @begin{Extend83}
1616 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1617 @Defn{extensions to Ada 83}
1618 This entire @Chg{Version=[3],New=[subclause],Old=[clause]} is new;
1619 protected units do not exist in Ada 83.
1620 @end{Extend83}
1621
1622 @begin{Extend95}
1623 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00397-01],ARef=[AI95-00399-01],ARef=[AI95-00401-01],ARef=[AI95-00419-01]}
1624 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1625 Protected types and single protected objects can be derived from one or
1626 more interfaces. Operations declared in the protected type can implement
1627 the primitive operations of an interface. @nt{Overriding_indicator}s can
1628 be used to specify whether or not a protected operation implements a
1629 primitive operation.]}
1630 @end{Extend95}
1631
1632 @begin{DiffWord95}
1633 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0009],ARef=[AI95-00137-01]}
1634 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Changed representation clauses
1635 to aspect clauses to reflect that they are used for more than just
1636 representation.]}
1637
1638 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00280-01]}
1639 @ChgAdded{Version=[2],Text=[Described what happens when an operation of a
1640 finalized protected object is called.]}
1641
1642 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
1643 @ChgAdded{Version=[2],Text=[Revised the note on operations of
1644 protected types to
1645 reflect that limited types do have an assignment operation, but not
1646 copying (@nt{assignment_statement}s).]}
1647
1648 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
1649 @ChgAdded{Version=[2],Text=[Revised the note on use of the name of
1650 a protected type within itself to reflect the exception for anonymous
1651 access types.]}
1652 @end{DiffWord95}
1653
1654 @begin{Incompatible2005}
1655 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0291-1]}
1656 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
1657 @b<Correction:> When an inherited subprogram is implemented by a protected
1658 function, the first parameter has to be an @key[in] parameter, but not
1659 an access-to-variable type. Original Ada 2005 allowed access-to-variable
1660 parameters in this case; the parameter will need to be changed to
1661 access-to-constant with the addition of the @key[constant] keyword.]}
1662 @end{Incompatible2005}
1663
1664 @begin{Extend2005}
1665 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1],ARef=[AI05-0267-1]}
1666 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
1667 An optional @nt{aspect_specification} can be used in a
1668 @nt{protected_type_declaration}, a @nt{single_protected_declaration},
1669 and a @nt{protected_body}. This is described in @RefSecNum{Aspect Specifications}.]}
1670 @end{Extend2005}
1671
1672 @begin{DiffWord2005}
1673 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0042-1]}
1674 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that an
1675 inherited subprogram of a progenitor is overridden when it is
1676 implemented by an entry or subprogram.]}
1677
1678 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0090-1]}
1679 @ChgAdded{Version=[3],Text=[@b<Correction:> Added the missing
1680 defining name in the no conflicting primitive operation rule.]}
1681 @end{DiffWord2005}
1682
1683 @begin{Extend2012}
1684 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0147-1]}
1685 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}
1686 @b<Corrigendum:> Null procedures and expression functions are allowed
1687 in protected bodies. We consider this an omission, as there is no
1688 reason why the convinient shorthand notations should not be allowed
1689 in this context.]}
1690 @end{Extend2012}
1691
1692
1693 @LabeledClause{Intertask Communication}
1694
1695 @begin{Intro}
1696 @Defn{intertask communication}
1697 @IndexSee{Term=[critical section],See=(intertask communication)}
1698 The primary means for intertask
1699 communication is provided by
1700 calls on entries and protected subprograms.
1701 Calls on protected subprograms allow coordinated access
1702 to shared data objects.
1703 Entry calls allow for blocking the caller until
1704 a given condition is satisfied (namely, that the corresponding entry is open
1705 @em see @RefSecNum(Entry Calls)),
1706 and then communicating data or control information directly
1707 with another task or
1708 indirectly via a shared protected object.
1709
1710 @end{Intro}
1711
1712 @begin{StaticSem}
1713 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0225-1],ARef=[AI05-0291-1]}
1714 @Leading@;@Chg{Version=[3],New=[@Defn2{Term=[target object],
1715 Sec=(of the name of an entry or a protected subprogram)}],
1716 Old=[@Defn2{Term=[target object],
1717 Sec=(of a call on an entry or a protected subprogram)}]}
1718 @Chg{Version=[3],New=[When a @nt{name} or @nt{prefix} denotes],Old=[Any call on]}
1719 an entry@Chg{Version=[3],New=[,],Old=[ or on a]}
1720 protected subprogram@Chg{Version=[3],New=[, or a
1721 prefixed view of a primitive subprogram of a limited interface whose
1722 first parameter is a controlling parameter, the @nt{name} or @nt{prefix}
1723 determines],Old=[ identifies]}
1724 a @i(target object)@Chg{Version=[3],New=[],Old=[ for the operation,
1725 which is either a task (for an entry call) or a protected object (for an entry
1726 call or a protected subprogram call). The target object is considered an
1727 implicit parameter to the operation, and is determined by the operation
1728 @nt<name> (or @nt<prefix>) used in the call on the operation]},
1729 as follows:
1730 @begin{Honest}
1731 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0291-1]}
1732 @ChgAdded{Version=[3],Text=[This wording uses "denotes" to mean "denotes a
1733 view of an entity" (when the term is used in Legality Rules), and "denotes an
1734 entity" (when the term is used in Dynamic Semantics rules). It does not mean
1735 "view of a declaration", as that would not include renames (a renames is not
1736 an entry or protected subprogram).]}
1737 @end{Honest}
1738
1739 @begin(Itemize)
1740 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0291-1]}
1741 If it is a @nt<direct_name> or expanded name
1742 that denotes the declaration (or body) of the operation, then
1743 the target object is implicitly specified to be
1744 the current instance of the task or protected unit
1745 immediately enclosing the operation;
1746 @Defn{internal call}
1747 @Chg{Version=[3],New=[],Old=[such ]}a call@Chg{Version=[3],New=[ using
1748 such a name],Old=[]} is defined to be an @i(internal call);
1749
1750 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0291-1]}
1751 If it is a @nt<selected_component> that is not
1752 an expanded name, then the target object is explicitly
1753 specified to be the @Chg{Version=[3],New=[],Old=[task or protected]} object
1754 denoted by the @nt<prefix> of the @nt<name>;
1755 @Defn{external call}
1756 @Chg{Version=[3],New=[],Old=[such ]}a call@Chg{Version=[3],New=[ using
1757 such a name],Old=[]} is defined to be an @i(external call);
1758 @begin{Discussion}
1759 For example:
1760 @begin{Example}
1761 @key[protected] @key[type] Pt @key[is]
1762 @key[procedure] Op1;
1763 @key[procedure] Op2;
1764 @key[end] Pt;
1765
1766 PO : Pt;
1767 Other_Object : Some_Other_Protected_Type;
1768
1769 @key[protected] @key[body] Pt @key[is]
1770 @key[procedure] Op1 @key[is] @key[begin] ... @key[end] Op1;
1771
1772 @key[procedure] Op2 @key[is]
1773 @key[begin]
1774 Op1; --@RI{ An internal call.}
1775 Pt.Op1; --@RI{ Another internal call.}
1776 PO.Op1; --@RI{ An external call. It the current instance is PO, then}
1777 --@RI{ this is a bounded error (see @RefSecNum{Protected Subprograms and Protected Actions}).}
1778 Other_Object.Some_Op; --@RI{ An external call.}
1779 @key[end] Op2;
1780 @key[end] Pt;
1781 @end{Example}
1782 @end{Discussion}
1783
1784 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0291-1]}
1785 If the @nt<name> or @nt<prefix> is a dereference
1786 (implicit or explicit) of an
1787 access-to-protected-subprogram value,
1788 then the target object is determined by the
1789 @nt<prefix> of the Access @nt<attribute_reference>
1790 that produced the access value originally@Chg{Version=[3],New=[; a],
1791 Old=[, and the]} call@Chg{Version=[3],New=[ using
1792 such a name],Old=[]} is defined to be an @i(external call);
1793
1794 If the @nt<name> or @nt<prefix> denotes a
1795 @nt<subprogram_renaming_declaration>,
1796 then the target object is as determined by the @nt<name> of the renamed
1797 entity.
1798
1799 @end(Itemize)
1800
1801 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0291-1]}
1802 @ChgAdded{Version=[3],Text=[A call on an entry or a protected subprogram either
1803 uses a @nt{name} or @nt{prefix} that determines a target object implicitly, as
1804 above, or is a call on (a non-prefixed view of) a primitive subprogram of a
1805 limited interface whose first parameter is a controlling parameter, in which
1806 case the target object is identified explicitly by the first parameter. This
1807 latter case is an @i<external call>.]}
1808
1809 @Defn2{Term=[target object],
1810 Sec=(of a @nt<requeue_statement>)}
1811 @Defn{internal requeue}
1812 @Defn{external requeue}
1813 A corresponding definition of target object applies
1814 to a @nt<requeue_statement> (see @RefSecNum(Requeue Statements)),
1815 with a corresponding distinction between an @i(internal requeue)
1816 and an @i(external requeue).
1817
1818 @end{StaticSem}
1819
1820 @begin{Legality}
1821 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
1822 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0225-1],ARef=[AI05-0291-1]}
1823 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[If a @nt{name} or
1824 @nt{prefix} determines a target object, and the name denotes],Old=[The view of
1825 the target protected object associated with a call of]}
1826 a protected @Chg{Version=[3],New=[entry],Old=[procedure]} or
1827 @Chg{Version=[3],New=[procedure, then the target object],Old=[entry]}
1828 shall be a variable@Chg{Version=[3],New=[, unless the
1829 @nt{prefix} is for an @nt{attribute_reference} to the Count
1830 attribute (see @RefSecNum{Task and Entry Attributes})],Old=[]}.]}
1831 @begin{Reason}
1832 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0225-1]}
1833 @ChgAdded{Version=[3],Text=[The point is to prevent any calls to such a
1834 @nt{name} whose target object is a constant view of a protected object,
1835 directly, or via an access value, renames, or generic formal
1836 subprogram. It is, however, legal to say P'Count in a protected function body,
1837 even though the protected object is a constant view there.]}
1838 @end{Reason}
1839 @begin{Ramification}
1840 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0291-1]}
1841 @ChgAdded{Version=[3],Text=[This rule does not apply to calls that are not to
1842 a prefixed view. Specifically a "normal" call to a primitive operation of a
1843 limited interface is not covered by this rule. In that case, the normal
1844 parameter passing mode checks will prevent passing a constant protected
1845 object to an operation implemented by a protected entry or procedure
1846 as the mode is required to be @key[in out] or @key[out].]}
1847 @end{Ramification}
1848
1849 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0166-1]}
1850 @ChgAdded{Version=[5],Text=[An internal call on a protected function shall not
1851 occur within a precondition expression (see @RefSecNum{Preconditions and Postconditions})
1852 of a protected operation nor within a @nt{default_expression} of a
1853 @nt{parameter_specification} of a protected operation.]}
1854
1855 @begin{Reason}
1856 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI125-0166-1]}
1857 @ChgAdded{Version=[5],Text=[These calls will be made before the start of the
1858 protected action, and thus would not be subject to the expected mutual
1859 exclusion. As such, they would be an automatic race condition (the state of
1860 the called object could change before the start of the protected action for
1861 the call on the protected entry or subprogram).]}
1862 @end{Reason}
1863
1864 @begin{Honest}
1865 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI125-0166-1]}
1866 @ChgAdded{Version=[5],Text=[@RefSecNum{Preconditions and Postconditions}
1867 actually defines "specific precondition expression"
1868 and "class-wide precondition expression". This rule is intended to apply to
1869 both.]}
1870 @end{Honest}
1871 @end{Legality}
1872
1873 @begin{RunTime}
1874 Within the body of a protected operation, the current instance
1875 (see @RefSecNum(The Context of Overload Resolution))
1876 of the immediately enclosing protected unit is determined by the target object
1877 specified (implicitly or explicitly) in the call (or requeue) on the
1878 protected operation.
1879 @begin{Honest}
1880 The current instance is defined in the same way
1881 within the body of a subprogram declared immediately within a
1882 @nt{protected_body}.
1883 @end{Honest}
1884
1885 Any call on a protected procedure or entry of a target
1886 protected object is defined to be an update to the object,
1887 as is a requeue on such an entry.
1888 @begin(Reason)
1889 Read/write access to the components of a protected
1890 object is granted while inside the body
1891 of a protected procedure or entry.
1892 Also, any protected entry call can change the value of the Count
1893 attribute, which represents an update.
1894 Any protected procedure call can result in servicing the entries,
1895 which again might change the value of a Count attribute.
1896 @end(Reason)
1897 @end{RunTime}
1898
1899 @begin{Syntax}
1900 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
1901 @AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<synchronization_kind>,Old=<>}>,
1902 rhs="@Chg{Version=[3],New=<By_Entry | By_Protected_Procedure | Optional>,Old=<>}"}
1903 @end{Syntax}
1904
1905 @begin{StaticSem}
1906 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0215-1]}
1907 @ChgAdded{Version=[3],Type=[Leading],Text=[For the declaration of a primitive
1908 procedure of a synchronized tagged type the following language-defined
1909 representation aspect may be specified with an @nt{aspect_specification} (see
1910 @RefSecNum{Aspect Specifications}):]}
1911
1912 @begin{Description}
1913 @ChgRef{Version=[3],Kind=[AddedNormal]}
1914 @ChgAdded{Version=[3],Text=[Synchronization@\If specified, the aspect definition
1915 shall be a @nt{synchronization_kind}.@AspectDefn{Synchronization}]}
1916
1917 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Synchronization],
1918 Text=[@ChgAdded{Version=[3],Text=[Defines whether a given primitive operation
1919 of a synchronized interface must be implemented by an entry or protected
1920 procedure.]}]}
1921
1922 @end{Description}
1923
1924 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
1925 @ChgAdded{Version=[3],Text=[Inherited subprograms inherit the Synchronization
1926 aspect, if any, from the corresponding subprogram of the parent or progenitor
1927 type. If an overriding operation does not have a directly specified
1928 Synchronization aspect then the Synchronization aspect of the inherited
1929 operation is inherited by the overriding operation.]}
1930 @end{StaticSem}
1931
1932 @begin{Legality}
1933
1934 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
1935 @ChgAdded{Version=[3],Text=[The @nt{synchronization_kind}
1936 By_Protected_Procedure shall not be applied to a primitive procedure of a task
1937 interface.]}
1938
1939 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
1940 @ChgAdded{Version=[3],Text=[A procedure for which the specified
1941 @nt{synchronization_kind} is By_Entry shall be implemented by an entry. A
1942 procedure for which the specified @nt{synchronization_kind} is
1943 By_Protected_Procedure shall be implemented by a protected procedure. A
1944 procedure for which the specified @nt{synchronization_kind} is Optional may be
1945 implemented by an entry or by a procedure (including a protected procedure).]}
1946
1947 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
1948 @ChgAdded{Version=[3],Text=[If a primitive procedure overrides an inherited
1949 operation for which the Synchronization aspect has been specified to be By_Entry
1950 or By_Protected_Procedure, then any specification of the aspect Synchronization
1951 applied to the overriding operation shall have the same
1952 @nt{synchronization_kind}.]}
1953
1954 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2]}
1955 @ChgAdded{Version=[3],Text=[@PDefn{generic contract issue}In addition to the
1956 places where @LegalityTitle normally apply (see
1957 @RefSecNum{Generic Instantiation}), these rules also apply in the
1958 private part of an instance of a generic unit.]}
1959 @end{Legality}
1960
1961 @begin{StaticSem}
1962
1963 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
1964 @ChgAdded{Version=[5],Type=[Leading],Text=[An @nt{expression} is
1965 @i<nonblocking-static> if it is one of the
1966 following:@Defn{nonblocking-static}@Defn2{Term=[expression],Sec=[nonblocking-static]}]}
1967
1968 @begin{Itemize}
1969 @ChgRef{Version=[5],Kind=[AddedNormal]}
1970 @ChgAdded{Version=[5],Text=[a static expression;]}
1971
1972 @ChgRef{Version=[5],Kind=[AddedNormal]}
1973 @ChgAdded{Version=[5],Text=[a Nonblocking @nt{attribute_reference};]}
1974
1975 @ChgRef{Version=[5],Kind=[AddedNormal]}
1976 @ChgAdded{Version=[5],Text=[a call to a predefined boolean logical operator
1977 @key[and] where each operand is nonblocking-static;]}
1978
1979 @ChgRef{Version=[5],Kind=[AddedNormal]}
1980 @ChgAdded{Version=[5],Text=[an @key[and then] short-circuit control form
1981 where each operand is nonblocking-static;]}
1982
1983 @ChgRef{Version=[5],Kind=[AddedNormal]}
1984 @ChgAdded{Version=[5],Text=[a parenthesized nonblocking-static @nt{expression}.]}
1985 @end{Itemize}
1986
1987 @begin{Reason}
1988 @ChgRef{Version=[5],Kind=[AddedNormal]}
1989 @ChgAdded{Version=[5],Text=[We define the term
1990 @ldquote@;nonblocking-static expression@rdquote so that
1991 nonblocking @nt{attribute_reference}s can be used to define the value of
1992 other nonblocking aspects, but we don't allow anything else with a value
1993 not known at compile-time.]}
1994 @end{Reason}
1995
1996 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0374-1]}
1997 @ChgAdded{Version=[5],Type=[Leading],Text=[For a program unit, task
1998 entry, formal package, formal
1999 subprogram, formal object of an anonymous access-to-subprogram type,
2000 enumeration literal, and for a subtype (including a formal subtype), the
2001 following language-defined operational aspect is defined:]}
2002
2003 @begin{Description}
2004 @ChgRef{Version=[5],Kind=[AddedNormal]}
2005 @ChgAdded{Version=[5],Text=[Nonblocking@\This aspect specifies the blocking
2006 restriction for the entity; it shall be specified by an @nt{expression},
2007 called a @i{nonblocking expression}.@Defn{nonblocking expression} If
2008 directly specified, the @nt{aspect_definition} shall be a
2009 nonblocking-static expression. The expected type for the @nt{expression} is
2010 the predefined type Boolean. @Redundant[The @nt{aspect_definition} can be
2011 omitted from the specification of this aspect; in that case the
2012 nonblocking expression for the entity is the enumeration literal
2013 True.@AspectDefn{Nonblocking}]]}
2014
2015 @ChgAspectDesc{Version=[5],Kind=[AddedNormal],Aspect=[Nonblocking],
2016 InitialVersion=[5],
2017 Text=[@ChgAdded{Version=[5],Text=[Specifies that an associated subprogram
2018 does not block.]}]}
2019
2020 @begin{TheProof}
2021 @ChgRef{Version=[5],Kind=[AddedNormal]}
2022 @ChgAdded{Version=[5],Text=[@RefSecNum{Aspect Specifications} allows
2023 omitting the aspect @nt{expression} for any aspect with type Boolean; we
2024 take advantage of that here.]}
2025 @end{TheProof}
2026
2027 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2028 @ChgAdded{Version=[5],Noprefix=[T],Text=[The Nonblocking aspect may be specified
2029 for all entities for which it is defined, except for protected operations and
2030 task entries. In particular, Nonblocking may be specified for generic formal
2031 parameters.]}
2032
2033 @begin{Ramification}
2034 @ChgRef{Version=[5],Kind=[AddedNormal]}
2035 @ChgAdded{Version=[5],Text=[The Nonblocking aspect cannot be specified for
2036 predefined operators or enumeration literals but we don't need to mention
2037 that above. One would have to declare a subprogram in order to specify the
2038 aspect in those cases, but that defines a user-defined subprogram which is
2039 itself not a predefined operator or an enumeration literal.]}
2040 @end{Ramification}
2041
2042 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2043 @ChgAdded{Version=[5],Noprefix=[T],Text=[When the nonblocking expression
2044 is static for an entity, the expression is evaluated to produce a static value
2045 for the aspect. When aspect Nonblocking is statically False for an entity, the
2046 entity might contain a potentially blocking operation; such an entity @i{allows
2047 blocking}. If the aspect is statically True for an entity, the entity is said to
2048 be @i{nonblocking}.@Defn{allows blocking}@Defn{nonblocking}@Defn2{Term=[blocking],Sec=[allows]}@Defn2{Term=[blocking],Sec=[non-]}]}
2049
2050 @begin{Discussion}
2051 @ChgRef{Version=[5],Kind=[AddedNormal]}
2052 @ChgAdded{Version=[5],Text=[We have to allow the aspect to be described as
2053 an expression inside of generic units, where the actual value of the
2054 aspect in an instance could be determined by the aspect of one or more
2055 actuals. Our intent is that the expression is always a static expression
2056 outside of any generic unit, and that in such contexts it is treated more
2057 like a static value than an expression.]}
2058 @end{Discussion}
2059
2060 @begin{Ramification}
2061 @ChgRef{Version=[5],Kind=[AddedNormal]}
2062 @ChgAdded{Version=[5],Text=[Specifying Nonblocking as False imposes
2063 no restrictions. Specifying Nonblocking as True imposes additional
2064 compile-time checks to prevent blocking, but does not prevent deadlock. A
2065 pragma Detect_Blocking can be used to ensure that Program_Error is raised
2066 in a deadlock situation.]}
2067 @end{Ramification}
2068
2069 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0374-1]}
2070 @ChgAdded{Version=[5],Noprefix=[T],Text=[For a generic unit @i{G}, if the
2071 aspect Nonblocking is statically true for @i{G} (by
2072 inheritance or specification), then the nonblocking expression for @i{G} is the
2073 @key[and] of the nonblocking attribute for each formal parameter of @i{G}.]}
2074
2075 @begin{Reason}
2076 @ChgRef{Version=[5],Kind=[AddedNormal]}
2077 @ChgAdded{Version=[5],Text=[This means that an instance of this generic will
2078 be nonblocking only if all of the formal parameters are nonblocking (see
2079 below). This is the most usable definition. If one wants a generic whose
2080 instantiations will always be nonblocking, Nonblocking can be specified on
2081 the formal parameters.]}
2082 @end{Reason}
2083
2084 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2085 @ChgAdded{Version=[5],Noprefix=[T],Text=[For a generic instantiation and
2086 entities declared within such an instance, the aspect is determined by the
2087 nonblocking expression for the corresponding entity of the generic unit, with
2088 any Nonblocking attributes of the generic formal parameters replaced by the
2089 appropriate nonblocking expression of the corresponding actual parameters. If
2090 the aspect is directly specified for an instance, the specified expression shall
2091 be static and have the same value as the nonblocking expression of the instance
2092 (after replacement).]}
2093
2094 @begin{Reason}
2095 @ChgRef{Version=[5],Kind=[AddedNormal]}
2096 @ChgAdded{Version=[5],Text=[We want to allow confirming aspects for
2097 instances, but nothing else. The @LegalityTitle of the generic body were
2098 checked assuming the nonblocking expression of the
2099 generic unit, and if that is changed, the instance body might
2100 make calls that allow blocking in subprograms that are nonblocking.]}
2101 @end{Reason}
2102
2103 @begin{Ramification}
2104 @ChgRef{Version=[5],Kind=[AddedNormal]}
2105 @ChgAdded{Version=[5],Text=[If the nonblocking expression of the
2106 instance is not static (if the instance is itself inside of a
2107 generic unit), then the Nonblocking aspect cannot be specified
2108 for the instance.]}
2109 @end{Ramification}
2110
2111 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2112 @ChgAdded{Version=[5],Noprefix=[T],Text=[For a (protected or task) entry, the
2113 Nonblocking aspect is the Boolean literal False.]}
2114
2115 @begin{Reason}
2116 @ChgRef{Version=[5],Kind=[AddedNormal]}
2117 @ChgAdded{Version=[5],Text=[An entry can be renamed as a procedure, so the
2118 value of the aspect has to be well-defined (as the attribute can be
2119 applied to a procedure). We do not want a nonblocking subprogram to be
2120 able to call an entry, no matter how it occurs, so the value ought to be
2121 False. Moreover, we do not want a subprogram that renames an entry to be
2122 able to override a nonblocking subprogram. We could have used individual
2123 rules for these cases, but there were already many of them, and this
2124 solution avoids the need for extra rules for entries.]}
2125 @end{Reason}
2126
2127 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2128 @ChgAdded{Version=[5],Noprefix=[T],Text=[For an enumeration literal, the
2129 Nonblocking aspect is the Boolean literal True.]}
2130
2131 @begin{Reason}
2132 @ChgRef{Version=[5],Kind=[AddedNormal]}
2133 @ChgAdded{Version=[5],Text=[Enumeration literals can be renamed as
2134 functions, and passed to generic formal functions, so we need to define
2135 the value of the aspect to ensure the other rules are meaningful.]}
2136 @end{Reason}
2137
2138 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2139 @ChgAdded{Version=[5],Noprefix=[T],Text=[For a predefined operator of an
2140 elementary type, the Nonblocking aspect is the Boolean literal True. For a
2141 predefined operator of a composite type, the Nonblocking aspect of the operator
2142 is the same as the Nonblocking aspect for the type.]}
2143
2144 @begin{Reason}
2145 @ChgRef{Version=[5],Kind=[AddedNormal]}
2146 @ChgAdded{Version=[5],Text=[Predefined operators of elementary types can
2147 never include any potentially blocking operations, so we want them to
2148 declare that. Record equality can be composed of operations including
2149 user-defined "=" operators, which might allow blocking. Array equality
2150 might use some record equality. So we have to have the possibility of
2151 allowing blocking for them. We don't just copy the Nonblocking aspect of
2152 the type in every case, as someone could declare an elementary type to
2153 allow blocking.]}
2154 @end{Reason}
2155
2156 @begin{Ramification}
2157 @ChgRef{Version=[5],Kind=[AddedNormal]}
2158 @ChgAdded{Version=[5],Text=[It's not possible to specify the nonblocking
2159 expression of a predefined operator; if an operator
2160 is declared in order to do that, it is no longer predefined.]}
2161 @end{Ramification}
2162
2163 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2164 @ChgAdded{Version=[5],Noprefix=[T],Text=[For a dereference of an
2165 access-to-subprogram type, the Nonblocking aspect of the designated subprogram
2166 is that of the access-to-subprogram type.]}
2167
2168 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0374-1]}
2169 @ChgAdded{Version=[5],Noprefix=[T],Text=[For the base type of a scalar (sub)type,
2170 the Nonblocking aspect is the Boolean literal True.]}
2171
2172 @begin{Reason}
2173 @ChgRef{Version=[5],Kind=[AddedNormal]}
2174 @ChgAdded{Version=[5],Text=[The first subtype of a scalar type can allow
2175 blocking (which can be useful so a predicate can allow blocking), but the
2176 base type is always Nonblocking. We need this so the Nonblocking value
2177 is well-defined for any subtype that is built from the base type (T'Base).
2178 T'Base of any scalar type, including a generic formal type, is always
2179 nonblocking.]}
2180 @end{Reason}
2181
2182 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2183 @ChgAdded{Version=[5],Noprefix=[T],Text=[For an inherited primitive dispatching
2184 subprogram that is null or abstract, the subprogram is nonblocking if and only
2185 if a corresponding subprogram of at least one ancestor is nonblocking. For any
2186 other inherited subprogram, it is nonblocking if and only if the corresponding
2187 subprogram of the parent is nonblocking.]}
2188
2189 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2190 @ChgAdded{Version=[5],Noprefix=[T],Text=[Unless directly specified, overridings
2191 of dispatching operations inherit this aspect.]}
2192
2193 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0374-1]}
2194 @ChgAdded{Version=[5],Noprefix=[T],Text=[Unless directly specified, for a formal
2195 subtype, formal package, or formal subprogram, the Nonblocking aspect is that of
2196 the actual subtype, package, or subprogram.]}
2197
2198 @begin{Reason}
2199 @ChgRef{Version=[5],Kind=[AddedNormal]}
2200 @ChgAdded{Version=[5],Text=[This means that Nonblocking legality
2201 checking for the actual parameters of the instance is only necessary
2202 when the aspect is explicitly specified for the formal type.]}
2203 @end{Reason}
2204
2205 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2206 @ChgAdded{Version=[5],Noprefix=[T],Text=[Unless directly specified, for a
2207 derived type, the Nonblocking aspect is that of the parent type.]}
2208
2209 @begin{Discussion}
2210 @ChgRef{Version=[5],Kind=[AddedNormal]}
2211 @ChgAdded{Version=[5],Text=[The expressions that can be specified for a
2212 derived type are limited by a @LegalityName, see below.]}
2213 @end{Discussion}
2214
2215 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2216 @ChgAdded{Version=[5],Noprefix=[T],Text=[Unless directly specified, for any
2217 other program unit, type, or formal object, the Nonblocking aspect of the entity
2218 is determined by the Nonblocking aspect for the innermost program unit enclosing
2219 the entity.]}
2220
2221 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2222 @ChgAdded{Version=[5],Noprefix=[T],Text=[If not specified for a library unit,
2223 the nonblocking expression is the Boolean literal True if the library unit is
2224 declared pure and is not a generic unit, or the Boolean literal False
2225 otherwise.]}
2226
2227 @end{Description}
2228
2229 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2230 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} S that
2231 denotes a subprogram (including a formal subprogram)}, the following attribute
2232 is defined:]}
2233
2234 @begin(description)
2235 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
2236 Leading=<F>, Prefix=<S>, AttrName=<Nonblocking>, ARef=[AI12-0064-2],
2237 InitialVersion=[5], Text=[@Chg{Version=[5],New=[Denotes whether
2238 subprogram S is considered nonblocking; the type
2239 of this attribute is the predefined type Boolean.],Old=[]}]}
2240
2241 @ChgRef{Version=[5],Kind=[AddedNormal]}
2242 @ChgAdded{Version=[5],Noprefix=[T],Text=[The @nt{prefix} S shall statically
2243 denote a subprogram.]}
2244
2245 @begin{Ramification}
2246 @ChgRef{Version=[5],Kind=[AddedNormal]}
2247 @ChgAdded{Version=[5],Text=[The evaluation of the @nt{prefix} S will have no
2248 effect, which is necessary for S'Nonblocking to be static. For the
2249 intended use in aspect specifications, we don't want any evaluation, as it
2250 would happen at some freezing point.]}
2251 @end{Ramification}
2252
2253 @ChgRef{Version=[5],Kind=[AddedNormal]}
2254 @ChgAdded{Version=[5],Noprefix=[T],Text=[S'Nonblocking represents the
2255 nonblocking expression of S; evaluation of S'Nonblocking evaluates that
2256 expression.]}
2257 @end(description)
2258
2259 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2260 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} P that
2261 denotes a package (including a formal package)}, the following attribute is defined:]}
2262
2263 @begin(description)
2264 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
2265 Leading=<F>, Prefix=<P>, AttrName=<Nonblocking>, ARef=[AI12-0064-2],
2266 InitialVersion=[5], Text=[@Chg{Version=[5],New=[Denotes whether
2267 package P is considered nonblocking; the type
2268 of this attribute is the predefined type Boolean.],Old=[]}]}@Comment{End of Annex text here.}
2269 @Chg{Version=[5],New=[P'Nonblocking represents the nonblocking expression of
2270 P; evaluation of P'Nonblocking evaluates that expression.],Old=[]}
2271 @end(description)
2272
2273 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2274 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} S that
2275 denotes a subtype (including formal subtypes)}, the following attribute is defined:]}
2276
2277 @begin(description)
2278 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
2279 Leading=<F>, Prefix=<S>, AttrName=<Nonblocking>, ARef=[AI12-0064-2], ARef=[AI12-0319-1], ARef=[AI12-0374-1],
2280 InitialVersion=[5], Text=[@Chg{Version=[5],New=[Denotes whether
2281 default initialization, finalization, assignment, predefined
2282 operators, and (in the case of
2283 access-to-subprogram subtypes) a subprogram designated by a value of
2284 subtype S are considered nonblocking; the type of this attribute is the
2285 predefined type Boolean.],Old=[]}]}@Comment{End of Annex text here.}
2286 @Chg{Version=[5],New=[S'Nonblocking represents the nonblocking expression of
2287 S; evaluation of S'Nonblocking evaluates that expression.],Old=[]}
2288 @end(description)
2289
2290 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0319-1]}
2291 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that
2292 denotes an object}, the following attribute is defined:]}
2293
2294 @begin(description)
2295 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
2296 Leading=<F>, Prefix=<X>, AttrName=<Nonblocking>, ARef=[AI12-0319-1], ARef=[AI12-0374-1],
2297 InitialVersion=[5], Text=[@Chg{Version=[5],New=[Denotes whether
2298 the subtype of X is considered nonblocking; the type of this
2299 attribute is the predefined type Boolean. X'Nonblocking represents the
2300 nonblocking expression of X; evaluation of X'Nonblocking evaluates that
2301 expression.],Old=[]}]}@Comment{End of Annex text here.}
2302 @Chg{Version=[5],New=[X'Nonblocking represents the nonblocking expression of
2303 X; evaluation of X'Nonblocking evaluates that expression.],Old=[]}
2304
2305 @begin{Honest}
2306 @ChgRef{Version=[5],Kind=[AddedNormal]}
2307 @ChgAdded{Version=[5],Text=[In the case when the @nt{prefix} represents the
2308 Storage_Pool of some type, this is the specific type of the associated pool
2309 object, if known.]}
2310 @end{Honest}
2311 @begin{Reason}
2312 @ChgRef{Version=[5],Kind=[AddedNormal]}
2313 @ChgAdded{Version=[5],Text=[This attribute, combined with rules found in
2314 @RefSecNum{Storage Management}, allow Acc'Storage_Pool'Nonblocking to
2315 describe whether the storage pool of an access type allows blocking.]}
2316 @end{Reason}
2317 @end(description)
2318
2319 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0374-1]}
2320 @ChgAdded{Version=[5],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that
2321 denotes an object of a class-wide type T'Class}, the following attribute
2322 is defined:]}
2323
2324 @begin(description)
2325 @Comment{We need to fix syntax in an AttrName; it works in the annex but not
2326 here.}
2327 @ChgAttribute{Version=[5],Kind=[AddedNormal],ChginAnnex=[T],
2328 Leading=<F>, Prefix=<X>, AttrName=<Nonblocking(dispatching_operation_set)>, ARef=[AI12-0374-1],
2329 InitialVersion=[5], Text=[@Chg{Version=[5],New=[X'Nonblocking(@nt{dispatching_operation_set})
2330 represents the @key[and] of the Nonblocking aspect of
2331 the tagged type @i<T1> identified by the tag of X, and the Nonblocking
2332 aspects of the dispatching operations of @i<T1> corresponding to the
2333 specified dispatching operations of T (or all dispatching operations
2334 of T if the set is the reserved word @key[all]).],Old=[]}]}@Comment{End of Annex text here.}
2335 @Chg{Version=[5],New=[If a @Syni{dispatching_}@nt{selector_name} within
2336 the set denotes multiple dispatching operations of T, the
2337 Nonblocking aspects of all of the corresponding dispatching operations
2338 of @i{T1} are @key[and]ed together.],Old=[]}
2339 @end(description)
2340
2341
2342 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0247-1]}
2343 @ChgAdded{Version=[5],Type=[Leading],Text=[The following are defined to be
2344 @i{potentially blocking} operations:@Defn{potentially blocking operation}
2345 @Defn{blocking, potentially}]}
2346
2347 @begin{Reason}
2348 @ChgRef{Version=[5],Kind=[AddedNormal]}
2349 @ChgAdded{Version=[5],Text=[The primary purpose of these rules is to define
2350 what operations are not allowed in a protected operation (blocking is not
2351 allowed). Some of these operations are not directly blocking. However, they
2352 are still treated as potentially blocking, because allowing them in a
2353 protected action might impose an undesirable implementation burden.]}
2354 @end{Reason}
2355
2356 @begin{Itemize}
2357 @ChgRef{Version=[5],Kind=[AddedNormal]}
2358 @ChgAdded{Version=[5],Text=[a @nt{select_statement};]}
2359
2360 @ChgRef{Version=[5],Kind=[AddedNormal]}
2361 @ChgAdded{Version=[5],Text=[an @nt{accept_statement};]}
2362
2363 @ChgRef{Version=[5],Kind=[AddedNormal]}
2364 @ChgAdded{Version=[5],Text=[an @nt{entry_call_statement}, or a call on
2365 a procedure that renames or is implemented by an entry;]}
2366
2367 @ChgRef{Version=[5],Kind=[AddedNormal]}
2368 @ChgAdded{Version=[5],Text=[a @nt{delay_statement};]}
2369
2370 @ChgRef{Version=[5],Kind=[AddedNormal]}
2371 @ChgAdded{Version=[5],Text=[an @nt{abort_statement};]}
2372
2373 @ChgRef{Version=[5],Kind=[AddedNormal]}
2374 @ChgAdded{Version=[5],Text=[task creation or activation;]}
2375
2376 @ChgRef{Version=[5],Kind=[AddedNormal]}
2377 @ChgAdded{Version=[5],Text=[during a protected action, an external call on a
2378 protected subprogram (or an external requeue) with the same target object as
2379 that of the protected action.]}
2380
2381 @begin{Reason}
2382 @ChgRef{Version=[5],Kind=[AddedNormal]}
2383 @ChgAdded{Version=[5],Text=[This is really a deadlocking call, rather than a
2384 blocking call, but we include it in this list for simplicity.]}
2385 @end{Reason}
2386
2387 @end{Itemize}
2388
2389 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2390 @ChgAdded{Version=[5],Text=[If a language-defined subprogram allows blocking,
2391 then a call on the subprogram is a potentially blocking operation.]}
2392
2393 @begin{Ramification}
2394 @ChgRef{Version=[5],Kind=[AddedNormal]}
2395 @ChgAdded{Version=[5],Text=[Calls on other subprograms that allow blocking
2396 are not themselves potentially blocking; the execution of the body
2397 could execute a potentially blocking operation.]}
2398
2399 @ChgRef{Version=[5],Kind=[AddedNormal]}
2400 @ChgAdded{Version=[5],Text=[A user-defined instance of a language-defined
2401 generic creates user-defined subprograms for the purpose of this rule.
2402 A dispatching call to a language-defined abstract subprogram always
2403 calls a user-defined concrete subprogram, so that too is not
2404 potentially blocking for the purposes of this rule.]}
2405 @end{Ramification}
2406
2407 @end{StaticSem}
2408
2409 @begin{Legality}
2410
2411 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0267-1]}
2412 @ChgAdded{Version=[5],Type=[Leading],Text=[A parallel construct or a nonblocking
2413 program unit shall not contain, other than within nested units with Nonblocking
2414 specified as statically False, a call on a callable entity for which the
2415 Nonblocking aspect is statically False, nor shall it contain any of the
2416 following:]}
2417
2418 @begin{Itemize}
2419 @ChgRef{Version=[5],Kind=[AddedNormal]}
2420 @ChgAdded{Version=[5],Text=[a @nt{select_statement};]}
2421
2422 @ChgRef{Version=[5],Kind=[AddedNormal]}
2423 @ChgAdded{Version=[5],Text=[an @nt{accept_statement};]}
2424
2425 @ChgRef{Version=[5],Kind=[AddedNormal]}
2426 @ChgAdded{Version=[5],Text=[a @nt{delay_statement};]}
2427
2428 @ChgRef{Version=[5],Kind=[AddedNormal]}
2429 @ChgAdded{Version=[5],Text=[an @nt{abort_statement};]}
2430
2431 @ChgRef{Version=[5],Kind=[AddedNormal]}
2432 @ChgAdded{Version=[5],Text=[task creation or activation.]}
2433 @end{Itemize}
2434
2435 @begin{Ramification}
2436 @ChgRef{Version=[5],Kind=[AddedNormal]}
2437 @ChgAdded{Version=[5],Text=[Implicit calls for finalization, storage pools,
2438 and the like are covered by the above prohibition. The rules above say
2439 @ldquote@;a call@rdquote, not @ldquote@;an explicit call@rdquote. Such calls
2440 are considered statically bound when that is possible, that is, when the
2441 controlling object has a known specific type (even if the actual
2442 implementation uses dispatching).]}
2443 @end{Ramification}
2444
2445 @begin{Discussion}
2446 @ChgRef{Version=[5],Kind=[AddedNormal]}
2447 @ChgAdded{Version=[5],Text=[We don't need to worry specially about
2448 entry calls (even if the entry has been renamed as a procedure), as they
2449 will be detected by the prohibition against calls to entities with the
2450 Nonblocking aspect False.]}
2451
2452 @ChgRef{Version=[5],Kind=[AddedNormal]}
2453 @ChgAdded{Version=[5],Text=[Similarly, we don't need to specially worry about
2454 subprograms of limited interfaces that are implemented by entries, as any
2455 such subprogram necessarily has the value statically False for the
2456 Nonblocking aspect, and thus is already covered by the prohibition against
2457 calling such subprograms.]}
2458 @end{Discussion}
2459
2460 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2461 @ChgAdded{Version=[5],Text=[For the purposes of the above rule, an
2462 @nt{entry_body} is considered nonblocking if the immediately enclosing protected
2463 unit is nonblocking.]}
2464
2465 @begin{Reason}
2466 @ChgRef{Version=[5],Kind=[AddedNormal]}
2467 @ChgAdded{Version=[5],Text=[An entry always allows blocking (by rule); but we
2468 want to be able to compile-time check for most violations of prohibition
2469 against potentially blocking operations in a protected action (see
2470 @RefSecNum{Protected Subprograms and Protected Actions}).
2471 We do that by using the nonblocking status of the protected unit as the
2472 controlling factor, and enforce that by not allowing the specification of
2473 the Nonblocking aspect for any protected operation.]}
2474 @end{Reason}
2475
2476 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0374-1]}
2477 @ChgAdded{Version=[5],Text=[For a subtype for which aspect Nonblocking is True,
2478 any predicate expression that applies to the subtype shall only contain
2479 constructs that are allowed immediately within a nonblocking program
2480 unit.]}
2481
2482 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2483 @ChgAdded{Version=[5],Text=[A subprogram shall be nonblocking if it overrides a
2484 nonblocking dispatching operation. An entry shall not implement a nonblocking
2485 procedure. If an inherited dispatching subprogram allows blocking, then the
2486 corresponding subprogram of each ancestor shall allow blocking.]}
2487
2488 @begin{Discussion}
2489 @ChgRef{Version=[5],Kind=[AddedNormal]}
2490 @ChgAdded{Version=[5],Text=[Rules elsewhere in the standard
2491 (@RefSecNum{Type Conversions} and @RefSecNum{Operations of Access Types})
2492 ensure that access-to-subprogram conversion and the Access attribute
2493 enforce nonblocking.]}
2494 @end{Discussion}
2495
2496 @begin{Ramification}
2497 @ChgRef{Version=[5],Kind=[AddedNormal]}
2498 @ChgAdded{Version=[5],Text=[A nonblocking subprogram can override one that
2499 allows blocking, but the reverse is illegal. Thus one can declare a Finalize
2500 subprogram to be nonblocking, even though it overrides a routine that allows
2501 blocking. (This works because a nonblocking subprogram allows a strict
2502 subset of the operations allowed in allows blocking subprograms, so calling
2503 such a subprogram as if it allows blocking @em as is necessary in a
2504 dispatching call @em is harmless.)]}
2505 @end{Ramification}
2506
2507 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2508 @ChgAdded{Version=[5],Text=[It is illegal to specify aspect Nonblocking for the
2509 full view of a type that has a partial view.]}
2510
2511 @begin{Ramification}
2512 @ChgRef{Version=[5],Kind=[AddedNormal]}
2513 @ChgAdded{Version=[5],Text=[The aspect should be specified on the partial view
2514 for such a type. This is necessary to prevent the predefined equality
2515 operator from being nonblocking in the partial view and allowing blocking in
2516 the full view.]}
2517 @end{Ramification}
2518
2519 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0374-1]}
2520 @ChgAdded{Version=[5],Text=[Aspect Nonblocking shall be specified for
2521 the first subtype of a derived
2522 type only if it fully conforms to the nonblocking expression of the ancestor
2523 subtype or if it is specified to have the Boolean literal True. Aspect
2524 Nonblocking shall be specified for a nonfirst
2525 subtype @i{S} only if it fully conforms to the nonblocking expression of the
2526 subtype identified in the @nt{subtype_indication} defining @i{S} or if it is
2527 specified to have the Boolean literal True. Aspect Nonblocking shall be
2528 specified for a first subtype @i{S} that completes an incomplete or partial
2529 view @i{P} only if it fully conforms to the nonblocking expression of the
2530 subtype @i{P} or if it is specified to have the Boolean literal True.]}
2531
2532 @begin{Reason}
2533 @ChgRef{Version=[5],Kind=[AddedNormal]}
2534 @ChgAdded{Version=[5],Text=[Boolean-valued aspects have a similar rule to
2535 the first rule here (see @RefSecNum{Aspect Specifications}), we want this
2536 one to work similarly. For the other rules, we need non-first subtypes
2537 and completions to allow blocking only if the original first subtype
2538 allows blocking, as that allows the programmer to know that any
2539 operation on any subtype of a type are nonblocking if the first
2540 subtype is nonblocking.]}
2541 @end{Reason}
2542
2543 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2544 @ChgAdded{Version=[5],Text=[If aspect Nonblocking is specified for an entity
2545 that is not a generic unit or declared inside of a generic unit, the
2546 @nt{aspect_definition} shall be a static expression.]}
2547
2548 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2549 @ChgAdded{Version=[5],Text=[If the prefix of a Nonblocking
2550 @nt{attribute_reference} denotes a generic unit @i<G>,
2551 the reference shall occur within the declarative region of @i<G>.]}
2552
2553 @begin{Reason}
2554 @ChgRef{Version=[5],Kind=[AddedNormal]}
2555 @ChgAdded{Version=[5],Text=[We want the value of Nonblocking attributes to be
2556 static so long as they occur outside of any generic unit. The Nonblocking
2557 aspect of a generic unit will often depend on the actual parameters of the
2558 unit, so it cannot be static (or have any well-defined value). We need this
2559 latter rule in case the attribute of a generic is used outside of the
2560 generic. Note that the previous rule makes it illegal to use such an
2561 attribute to specify aspect Nonblocking outside of a generic, but we don't
2562 want to allow any other uses since it does not have a known value until
2563 instantiated.]}
2564 @end{Reason}
2565
2566 @begin{Ramification}
2567 @ChgRef{Version=[5],Kind=[AddedNormal]}
2568 @ChgAdded{Version=[5],Text=[This rule does not apply to instances of generic
2569 units and entities declared within them.]}
2570 @end{Ramification}
2571
2572 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0319-1]}
2573 @ChgAdded{Version=[5],Type=[Leading],Text=[For a composite type that is
2574 nonblocking:]}
2575
2576 @begin{Itemize}
2577 @ChgRef{Version=[5],Kind=[AddedNormal]}
2578 @ChgAdded{Version=[5],Text=[All component subtypes shall be nonblocking;]}
2579
2580 @ChgRef{Version=[5],Kind=[AddedNormal]}
2581 @ChgAdded{Version=[5],Text=[For a record type or extension, every call in the
2582 @nt{default_expression} of a component (including discriminants) shall
2583 call an operation that is nonblocking;]}
2584
2585 @ChgRef{Version=[5],Kind=[AddedNormal]}
2586 @ChgAdded{Version=[5],Text=[For a controlled type, the Initialize, Finalize,
2587 and Adjust (if any) subprograms shall be nonblocking.]}
2588
2589 @begin{Reason}
2590 @ChgRef{Version=[5],Kind=[AddedNormal]}
2591 @ChgAdded{Version=[5],Text=[These rules ensure that if a type is nonblocking, the
2592 default initialization, finalization, and assignment of the type
2593 are also nonblocking. This allows the use of the nonblocking attribute
2594 of a generic formal type to describe whether these operations of the type
2595 allow blocking.]}
2596
2597 @ChgRef{Version=[5],Kind=[AddedNormal]}
2598 @ChgAdded{Version=[5],Text=[Default initialization, finalization, and
2599 assignment of elementary types are always nonblocking, so we don't need any
2600 rules for those.]}
2601 @end{Reason}
2602 @end{Itemize}
2603
2604 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2605 @ChgAdded{Version=[5],Type=[Leading],Text=[The predefined equality operator for
2606 a composite type is illegal if it is nonblocking and, for a record type, it is
2607 not overridden by a primitive equality operator, and:]}
2608
2609 @begin{Itemize}
2610 @ChgRef{Version=[5],Kind=[AddedNormal]}
2611 @ChgAdded{Version=[5],Text=[for a record type, the parent primitive "="
2612 allows blocking; or]}
2613
2614 @ChgRef{Version=[5],Kind=[AddedNormal]}
2615 @ChgAdded{Version=[5],Text=[any component that has a record type that has a
2616 primitive "=" that allows blocking; or]}
2617
2618 @ChgRef{Version=[5],Kind=[AddedNormal]}
2619 @ChgAdded{Version=[5],Text=[any component that has a non-record type that
2620 has a predefined "=" that allows blocking.]}
2621 @end{Itemize}
2622
2623 @begin{Ramification}
2624 @ChgRef{Version=[5],Kind=[AddedNormal]}
2625 @ChgAdded{Version=[5],Text=[This applies to both record and array "=".]}
2626
2627 @ChgRef{Version=[5],Kind=[AddedNormal]}
2628 @ChgAdded{Version=[5],Text=[This check occurs when the equality operator is
2629 declared, so this rule effectively makes the type illegal if the rule is
2630 violated.]}
2631 @end{Ramification}
2632
2633 @begin{Reason}
2634 @ChgRef{Version=[5],Kind=[AddedNormal]}
2635 @ChgAdded{Version=[5],Text=[We don't need to check this when the operator is
2636 overridden for a record type, as the body of the new definition of equality
2637 will enforce the rules, and there is no case where the predefined operator
2638 will re-emerge. We do have to check this for array types even if the
2639 operator is overridden, as the predefined operator will re-emerge in
2640 generics and record equality.]}
2641 @end{Reason}
2642
2643 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2644 @ChgAdded{Version=[5],Type=[Leading],Text=[In a generic instantiation (after
2645 replacement in the nonblocking expressions by values of the actuals as described
2646 previously):]}
2647
2648 @begin{Itemize}
2649 @ChgRef{Version=[5],Kind=[AddedNormal]}
2650 @ChgAdded{Version=[5],Text=[the actual subprogram corresponding to a
2651 nonblocking formal subprogram shall be nonblocking @Redundant[(an actual that
2652 is an entry is not permitted in this case)];]}
2653
2654 @ChgRef{Version=[5],Kind=[AddedNormal]}
2655 @ChgAdded{Version=[5],Text=[the actual type corresponding to a nonblocking
2656 formal private, derived, array, or access-to-subprogram type shall be
2657 nonblocking;]}
2658
2659 @begin{Ramification}
2660 @ChgRef{Version=[5],Kind=[AddedNormal]}
2661 @ChgAdded{Version=[5],Text=[We do not require matching for formal
2662 scalar or access-to-object types, as their predefined operators are
2663 always nonblocking (and they re-emerge in the generic unit) @em the
2664 nonblocking status of the type has no impact.]}
2665 @end{Ramification}
2666
2667 @ChgRef{Version=[5],Kind=[AddedNormal]}
2668 @ChgAdded{Version=[5],Text=[the actual object corresponding to a formal object
2669 of a nonblocking access-to-subprogram type shall be of a nonblocking
2670 access-to-subprogram type;]}
2671
2672 @ChgRef{Version=[5],Kind=[AddedNormal]}
2673 @ChgAdded{Version=[5],Text=[the actual instance corresponding to a nonblocking
2674 formal package shall be nonblocking.]}
2675
2676 @end{Itemize}
2677
2678 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2679 @ChgAdded{Version=[5],Text=[@PDefn{generic contract issue}In addition to the
2680 places where @LegalityTitle normally apply (see
2681 @RefSecNum{Generic Instantiation}), the above rules also apply in the private
2682 part of an instance of a generic unit.]}
2683
2684 @begin{Ramification}
2685 @ChgRef{Version=[5],Kind=[AddedNormal]}
2686 @ChgAdded{Version=[5],Text=[For a generic formal parameter to be nonblocking
2687 (thus, for these rules to apply), it has to explicitly specify aspect
2688 Nonblocking to be True. In particular, these rules do not apply when it
2689 specifies aspect Nonblocking to be an expression involving attribute
2690 Nonblocking of a generic formal parameter. However, in such a case, these
2691 rules do apply in the instance of the specification of the generic unit (the
2692 normal re-checking is needed). For instance, the body of an expression
2693 function might make a prohibited call.]}
2694 @end{Ramification}
2695
2696 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2697 @ChgAdded{Version=[5],Text=[A program unit @i{P} declared inside of a generic
2698 unit but not in a generic body or that is a generic specification not declared
2699 in a generic unit is considered nonblocking for the purposes of checking the
2700 restrictions on a nonblocking unit only if the value of its Nonblocking aspect
2701 is statically True. For the purposes of checks in @i{P}, a call to a subprogram
2702 is considered nonblocking unless the value of its Nonblocking aspect is
2703 statically False.]}
2704
2705 @begin{Reason}
2706 @ChgRef{Version=[5],Kind=[AddedNormal]}
2707 @ChgAdded{Version=[5],Text=[This is a typical
2708 @ldquote@;assume-the-best@rdquote rule. We only make checks if we know the
2709 nonblocking status of both @i<P> and the called subprogram. All other checks
2710 will be performed when the generic unit is instantiated. We used the awkward
2711 @ldquote@;inside of a generic unit but not in a generic body@rdquote so that
2712 a generic specification declared inside of a generic body uses the following
2713 @ldquote@;assume-the-worst@rdquote rule.]}
2714 @end{Reason}
2715
2716 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2717 @ChgAdded{Version=[5],Type=[Leading],Text=[A program unit @i{P} declared inside
2718 of a generic body or that is a generic body is considered nonblocking for the
2719 purposes of checking the restrictions on a nonblocking unit unless the value of
2720 its Nonblocking aspect is statically False. For the purposes of checks in @i{P},
2721 a call to a subprogram is considered to allow blocking unless:]}
2722
2723 @begin{Itemize}
2724 @ChgRef{Version=[5],Kind=[AddedNormal]}
2725 @ChgAdded{Version=[5],Text=[the value of its Nonblocking aspect is statically
2726 True, or]}
2727
2728 @ChgRef{Version=[5],Kind=[AddedNormal]}
2729 @ChgAdded{Version=[5],Text=[its nonblocking expression (that is, Nonblocking
2730 aspect) conforms exactly to that of @i{P}, or conforms to some part of the
2731 nonblocking expression of @i{P} that is combined with the remainder of the
2732 nonblocking expression of @i{P} by one or more @key[and] or @key[and then]
2733 operations.]}
2734 @end{Itemize}
2735
2736 @begin{Ramification}
2737 @ChgRef{Version=[5],Kind=[AddedNormal]}
2738 @ChgAdded{Version=[5],Text=[That is, if the aspect of the program unit is
2739 specified (directly or via inheritance) with any non-static Nonblocking
2740 aspects, it is considered to be a nonblocking program unit for the purposes of
2741 making checks. This is a typical @ldquote@;assume-the-worst@rdquote rule.]}
2742 @end{Ramification}
2743
2744 @begin{Reason}
2745 @ChgRef{Version=[5],Kind=[AddedNormal]}
2746 @ChgAdded{Version=[5],Text=[The second part allows calls on subprograms with
2747 Nonblocking aspects of Formal'Nonblocking, so long as the Nonblocking aspect
2748 of @i<P> is some formula that contains Formal'Nonblocking combined with
2749 @key[and]. This ensures that P will always allow blocking if the actual for
2750 Formal turns out to allow blocking.]}
2751
2752 @ChgRef{Version=[5],Kind=[AddedNormal]}
2753 @ChgAdded{Version=[5],Type=[Leading],Text=[Without this rule, we'd allow calls
2754 on formals in any body subprogram, even if the subprogram did not include
2755 the formal in its Nonblocking aspect. For instance:]}
2756
2757 @begin{Example}
2758 @ChgRef{Version=[5],Kind=[AddedNormal]}
2759 @ChgAdded{Version=[5],Text=[@key[procedure] Blah @key[with] Formal1'Blocking @key[is]
2760 @key[begin]
2761 Formal2;
2762 @key[end] Blah;]}
2763 @end{Example}
2764
2765 @ChgRef{Version=[5],Kind=[AddedNormal]}
2766 @ChgAdded{Version=[5],Text=[If Formal1 is nonblocking and Formal2 allows
2767 blocking, then we'd have a nonblocking routine calling a routine that might
2768 block. That has to be prevented as this is
2769 @ldquote@;assume-the-worst@rdquote checking.]}
2770 @end{Reason}
2771
2772 @begin{Honest}
2773 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0319-1]}
2774 @ChgAdded{Version=[5],Text=[For checking in @i{P}, default initialization,
2775 finalization, assignment, or conversion to a formal subtype @i{F}
2776 is considered to call subprograms that have the nonblocking aspect of
2777 @i{F}'Nonblocking, and this is checked for conformance against that of
2778 @i{P} as described above. Note that the nonblocking aspect includes the
2779 evaluation of any predicate for the subtype.]}
2780
2781 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0319-1]}
2782 @ChgAdded{Version=[5],Text=[Similarly, for checking in @i{P}, the implicit
2783 calls associated with an @nt{allocator} of an access type @i{A} or a use
2784 of attribute @i{A}'Storage_Size are
2785 considered to call subprograms that have the nonblocking aspect of
2786 @i{A}'Storage_Pool'Nonblocking, and this is checked for conformance against
2787 that of @i{P} as described above.]}
2788 @end{Honest}
2789
2790 @end{Legality}
2791
2792 @begin{Notes}
2793 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
2794 @ChgAdded{Version=[3],Text=[The @nt{synchronization_kind} By_Protected_Procedure
2795 implies that the operation will not block.]}
2796 @end{Notes}
2797
2798 @begin{DiffWord95}
2799 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
2800 @ChgAdded{Version=[2],Text=[Added a @LegalityName to make it crystal-clear
2801 that the protected object of an entry or procedure call must be a variable.
2802 This rule was implied by the @RuntimeTitle here, along with the
2803 @StaticSemTitle of @RefSecNum{Objects and Named Numbers}, but it is much
2804 better to explicitly say it. While many implementations have gotten this
2805 wrong, this is not an incompatibility @em allowing updates of protected
2806 constants has always been wrong.]}
2807 @end{DiffWord95}
2808
2809 @begin{Extend2005}
2810 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
2811 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2812 Added the Synchronization aspect to allow
2813 specifying that an interface procedure is really an entry or a
2814 protected procedure.]}
2815 @end{Extend2005}
2816
2817 @begin{DiffWord2005}
2818 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0225-1]}
2819 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified that the target object
2820 of any name denoted a protected procedure or entry can never be a constant
2821 (other than for the 'Count attribute). This closes holes involving calls to
2822 access-to-protected, renaming as a procedure, and generic formal subprograms.]}
2823 @end{DiffWord2005}
2824
2825 @begin{Inconsistent2012}
2826 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
2827 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}
2828 Calls on procedures that rename an entry or are implemented by an entry
2829 are now defined to be potentially blocking.
2830 This means that such a call now might raise Program_Error. However, it
2831 never made sense for some entry calls to be excluded from being potentially
2832 blocking, and we expect that most implementations already treated all entry
2833 calls the same way. Thus do not expect this wording change to actually
2834 change the behavior of any implementation, and thus no program will change.]}
2835 @end{Inconsistent2012}
2836
2837 @begin{Incompatible2012}
2838 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0166-1]}
2839 @ChgAdded{Version=[5],Text=[@Defn{incompatibilities with Ada 2012}
2840 @b<Correction:> Internal protected calls are now prohibited in preconditions
2841 and default expressions of protected operations. These were allowed in
2842 Ada 2012, but as they cause race conditions and as most existing
2843 Ada 95 compilers crash when given such a default parameter, we expect
2844 such code to be extremely rare.]}
2845 @end{Incompatible2012}
2846
2847 @begin{Extend2012}
2848 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2],ARef=[AI12-0319-1],ARef=[AI12-0374-1]}
2849 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2850 Aspect Nonblocking is new; it allows compile-time checks to prevent
2851 using potentially blocking operations in contexts where that is not
2852 allowed.]}
2853 @end{Extend2012}
2854
2855
2856 @LabeledSubClause{Protected Subprograms and Protected Actions}
2857
2858 @begin{Intro}
2859 @Defn{protected subprogram}
2860 @Defn{protected procedure}
2861 @Defn{protected function}
2862 A @i{protected subprogram} is a subprogram declared immediately
2863 within a @nt{protected_definition}.
2864 Protected procedures provide exclusive read-write access
2865 to the data of a protected object; protected functions provide
2866 concurrent read-only access to the data.
2867 @begin{Ramification}
2868 A subprogram declared immediately within a @nt{protected_body} is not a
2869 protected subprogram; it is an intrinsic subprogram.
2870 See @RefSec{Conformance Rules}.
2871 @end{Ramification}
2872 @end{Intro}
2873
2874 @begin{StaticSem}
2875 @Redundant[Within the body of a protected function
2876 (or a function declared immediately within a @nt<protected_body>),
2877 the current instance of the enclosing protected unit is defined to be a
2878 constant
2879 (that is, its subcomponents may be read but not updated).
2880 Within the body of a protected procedure
2881 (or a procedure declared immediately within a @nt<protected_body>),
2882 and within an @nt<entry_body>,
2883 the current instance is defined to be a variable
2884 (updating is permitted).]
2885 @begin(TheProof)
2886 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0120-1]}
2887 @ChgAdded{Version=[3],Text=[All constant views are defined in
2888 @RefSec{Objects and Named Numbers}, anything not named there
2889 is a variable view.]}
2890 @end(TheProof)
2891 @begin(Ramification)
2892 The current instance is like an implicit parameter,
2893 of mode @key(in) for a protected function, and of mode @key(in out)
2894 for a protected procedure (or protected entry).
2895 @end(Ramification)
2896
2897 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0129-1]}
2898 @ChgAdded{Version=[4],Type=[Leading],Text=[For a type declared by a
2899 @nt{protected_type_declaration} or for the
2900 anonymous type of an object declared by a @nt{single_protected_declaration},
2901 the following language-defined type-related representation aspect
2902 may be specified:]}
2903
2904 @begin{Description}
2905 @ChgRef{Version=[4],Kind=[Added]}
2906 @ChgAdded{Version=[4],Text=[Exclusive_Functions@\The type of aspect
2907 Exclusive_Functions is Boolean. If not specified (including by inheritance),
2908 the aspect is False.@AspectDefn{Exclusive_Functions}]}
2909
2910 @ChgRef{Version=[4],Kind=[Added]}
2911 @ChgAdded{Version=[4],Text=[@\A value of True for this aspect indicates that
2912 protected functions behave in the same way as protected procedures
2913 with respect to mutual exclusion and queue servicing (see below).]}
2914
2915 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Exclusive_Functions],
2916 Text=[@ChgAdded{Version=[4],Text=[Specifies mutual exclusion behavior of
2917 protected functions in a protected type.]}]}
2918 @end{Description}
2919
2920 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0129-1]}
2921 @ChgAdded{Version=[4],Text=[A protected procedure or entry is an @i<exclusive>
2922 protected operation.@Defn2{Term=[exclusive],Sec=[protected operation]} A
2923 protected function of a protected type @i<P> is an exclusive protected
2924 operation if the Exclusive_Functions aspect of @i<P> is True.]}
2925
2926 @end{StaticSem}
2927
2928 @begin{RunTime}
2929
2930 @PDefn2{Term=[execution], Sec=(protected subprogram call)}
2931 For the execution of a call on a protected subprogram,
2932 the evaluation of the @nt<name> or @nt<prefix>
2933 and of the parameter associations,
2934 and any assigning back of @key[in out] or @key[out] parameters,
2935 proceeds as for a normal subprogram call (see @RefSecNum{Subprogram Calls}).
2936 If the call is an internal call (see @RefSecNum(Intertask Communication)),
2937 the body of the subprogram
2938 is executed as for a normal subprogram call.
2939 If the call is an external call, then
2940 the body of the subprogram is executed as part of a new
2941 @i(protected action) on the target protected object;
2942 the protected action completes after the body of the
2943 subprogram is executed.
2944 @Redundant[A protected action can also be started by an entry call
2945 (see @RefSecNum{Entry Calls}).]
2946
2947 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0129-1]}
2948 @leading@Defn{protected action}
2949 A new protected action is not started on a protected object
2950 while another protected action on the same protected object is underway,
2951 unless both actions are the result of a call on a
2952 @Chg{Version=[4],New=[nonexclusive ],Old=[]}protected function.
2953 This rule is expressible in terms of the execution resource
2954 associated with the protected object:
2955 @begin(Itemize)
2956 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0129-1]}
2957 @Defn2{Term=[protected action], Sec=(start)}
2958 @Defn2{Term=[acquire], Sec=(execution resource associated with protected object)}
2959 @i(Starting) a protected action on a protected object
2960 corresponds to @i(acquiring) the execution resource associated
2961 with the protected object, either
2962 for @Chg{Version=[4],New=[exclusive read-write],Old=[concurrent read-only]}
2963 access if the protected action is for a call on @Chg{Version=[4],New=[an
2964 exclusive protected operation],Old=[a protected function]}, or
2965 for @Chg{Version=[4],New=[concurrent read-only],Old=[exclusive read-write]}
2966 access otherwise;
2967
2968 @Defn2{Term=[protected action], Sec=(complete)}
2969 @Defn2{Term=[release], Sec=(execution resource associated with protected object)}
2970 @i(Completing) the protected action
2971 corresponds to @i(releasing) the associated execution resource.
2972 @end(Itemize)
2973
2974 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0129-1]}
2975 @Redundant[After performing an @Chg{Version=[4],New=[exclusive
2976 protected ],Old=[]}operation on a protected object@Chg{Version=[4],New=[],Old=[
2977 other than a call on a protected function]}, but prior
2978 to completing the associated protected action,
2979 the entry queues (if any)
2980 of the protected object are
2981 serviced (see @RefSecNum(Entry Calls)).]
2982
2983 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0119-1]}
2984 @ChgAdded{Version=[5],Text=[If a parallel construct occurs within a protected
2985 action, no new logical threads of control are created. Instead, each element of
2986 the parallel construct that would have become a separate logical thread of
2987 control executes on the logical thread of control that is performing the
2988 protected action. If there are multiple such elements initiated at the same
2989 point, they execute in an arbitrary order.]}
2990
2991 @begin{Reason}
2992 @ChgRef{Version=[5],Kind=[AddedNormal]}
2993 @ChgAdded{Version=[5],Text=[It would be feasible to allow multiple logical
2994 threads of control within a protected action, but it would significantly
2995 complicate the definition of @ldquote@;sequential@rdquote and
2996 @ldquote@;concurrent@rdquote actions, since we generally presume that
2997 everything occuring within protected
2998 actions of a given protected object is sequential. We could simply
2999 disallow any use of parallel constructs, but that seems unnecessary,
3000 particularly as a parallel construct might be buried within a
3001 subprogram that is declared Nonblocking.]}
3002 @end{Reason}
3003
3004 @end{RunTime}
3005
3006 @begin{Bounded}
3007 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2]}
3008 @ChgDeleted{Version=[5],Type=[Leading],Text=[]}@Comment{To make "Leading" conditional}
3009 @PDefn2{Term=(bounded error),Sec=(cause)}
3010 During a protected action, it is a bounded error to invoke an operation that
3011 is @Chg{Version=[5],New=[potentially blocking (see
3012 @RefSecNum{Intertask Communication}).],Old=[@i(potentially blocking).
3013 @Defn{potentially blocking operation}
3014 @Defn{blocking, potentially}
3015 The following are defined to be potentially blocking operations:]}
3016 @begin{NotIso}
3017 @ChgAdded{Version=[5],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 9
3018 through 16 were moved to @RefSecNum{Intertask Communication}.>}]}@Comment{This message
3019 should be deleted if the paragraphs are ever renumbered.}
3020 @end{NotIso}
3021 @begin{Reason}
3022 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg],ARef=[AI12-0064-2]}
3023 @ChgDeleted{Version=[5],Text=[Some of these operations are not directly
3024 blocking. However, they are still treated as bounded errors during a protected
3025 action, because allowing them might impose an undesirable implementation
3026 burden.]}
3027 @end{Reason}
3028 @begin{itemize}
3029 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3030 @ChgDeleted{Version=[5],Text=[a @nt{select_statement};]}
3031
3032 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3033 @ChgDeleted{Version=[5],Text=[an @nt{accept_statement};]}
3034
3035 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3036 @ChgDeleted{Version=[5],Text=[an @nt{entry_call_statement};]}
3037
3038 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3039 @ChgDeleted{Version=[5],Text=[a @nt{delay_statement};]}
3040
3041 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3042 @ChgDeleted{Version=[5],Text=[an @nt{abort_statement};]}
3043
3044 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3045 @ChgDeleted{Version=[5],Text=[task creation or activation;]}
3046
3047 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3048 @ChgDeleted{Version=[5],Text=[an external call on a protected subprogram (or an
3049 external requeue) with the same target object as that of the protected action;]}
3050 @begin(Reason)
3051 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3052 @ChgDeleted{Version=[5],Text=[This is really a deadlocking call, rather than a
3053 blocking call, but we include it in this list for simplicity.]}
3054 @end(Reason)
3055
3056 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3057 @ChgDeleted{Version=[5],Text=[a call on a subprogram whose body contains a
3058 potentially blocking operation.]}
3059 @begin(Reason)
3060 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3061 @ChgDeleted{Version=[5],Text=[This allows an implementation to check and raise
3062 Program_Error as soon as a subprogram is called, rather than waiting to find
3063 out whether it actually reaches the potentially blocking operation. This in
3064 turn allows the potentially blocking operation check to be performed prior to
3065 run time in some environments.]}
3066 @end(Reason)
3067 @end{itemize}
3068
3069 @Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}
3070 If the bounded error is detected, Program_Error is raised.
3071 If not detected, the bounded error
3072 might result in deadlock or a (nested)
3073 protected action on the same target object.
3074
3075 @begin{Discussion}
3076 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00305-01]}
3077 @ChgAdded{Version=[2],Text=[By @lquotes@;nested protected action@rquotes,
3078 we mean that an additional protected action can be started by another task
3079 on the same protected object. This means that mutual exclusion may be broken
3080 in this bounded error case. A way to ensure that this does not happen is to use
3081 pragma Detect_Blocking (see @RefSecNum{Pragma Detect_Blocking}).]}
3082 @end{Discussion}
3083
3084 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2],ARef=[AI12-0247-1]}
3085 @Chg{Version=[5],New=[During a protected action, a call on a subprogram whose
3086 body contains a potentially blocking operation is a bounded error.
3087 @PDefn2{Term=(bounded error),Sec=(cause)}
3088 @Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}
3089 If the bounded error is detected, Program_Error is raised; otherwise, the call proceeds
3090 normally. ],Old=[Certain language-defined subprograms are potentially blocking.
3091 In particular, the subprograms of
3092 the language-defined input-output packages that manipulate
3093 files (implicitly or explicitly) are potentially blocking.
3094 Other potentially blocking subprograms are identified
3095 where they are defined.
3096 When not specified as potentially blocking,
3097 a language-defined subprogram is nonblocking.]}
3098 @begin{Discussion}
3099 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00178-01]}
3100 @ChgRef{Version=[5],Kind=[DeletedNoDelMsg]}
3101 @ChgDeleted{Version=[5],Text=[@Chg{Version=[2],New=[Any subprogram in a language-defined input-output
3102 package that has a file parameter or result or operates on a default file is
3103 considered to manipulate a file. An instance of a language-defined input-output
3104 generic package provides subprograms that are covered by this rule. The only
3105 subprograms in language-defined input-output packages not covered by this rule
3106 (and thus not potentially blocking) are the Get and Put routines that take
3107 string parameters defined in the packages nested in Text_IO.],Old=[]}]}@ChgNote{This
3108 was the resolution of a ramification.}
3109 @end{Discussion}
3110 @begin{Reason}
3111 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0247-1]}
3112 @ChgAdded{Version=[5],Text=[This allows an implementation to check and raise
3113 Program_Error as soon as a subprogram is called, rather than waiting to find
3114 out whether it actually reaches the potentially blocking operation. If the
3115 call proceeds normally, reaching the potentially blocking operation is a
3116 separate bounded error, covered by the previous rules.]}
3117 @end{Reason}
3118 @end{Bounded}
3119
3120 @begin{Notes}
3121 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0276-1]}
3122 If two tasks both try to start a protected action
3123 on a protected object, and at most one is calling
3124 a protected @Chg{Version=[5],New=[nonexclusive ],Old=[]}function,
3125 then only one of the tasks can proceed.
3126 Although the other task cannot proceed, it is not considered
3127 blocked, and it might be consuming processing resources while it
3128 awaits its turn. @Chg{Version=[5],New=[Unless there is an admission
3129 policy (see @RefSecNum{Admission Policies}) in effect, there],Old=[There]}
3130 is no language-defined ordering or queuing
3131 presumed for tasks competing to start a protected action @em
3132 on a multiprocessor such tasks might use busy-waiting; for
3133 @Chg{Version=[5],New=[further ],Old=[]}monoprocessor
3134 @Chg{Version=[5],New=[and multiprocessor ],Old=[]}considerations,
3135 see @RefSec{Priority Ceiling Locking}.
3136 @begin{Discussion}
3137 The intended implementation on a multi-processor is in terms of
3138 @lquotes@;spin locks@rquotes@; @em the waiting task will spin.
3139 @end{Discussion}
3140
3141 The body of a protected unit may contain declarations and bodies for local
3142 subprograms. These are not visible outside the protected unit.
3143
3144 The body of a protected function can contain internal calls
3145 on other protected functions, but not protected procedures,
3146 because the current instance is a constant.
3147 On the other hand, the body of a protected procedure
3148 can contain internal calls on both protected functions and procedures.
3149
3150 From within a protected action,
3151 an internal call on a protected subprogram,
3152 or an external call on a protected subprogram with a different
3153 target object is not considered a potentially blocking operation.
3154 @begin(Reason)
3155 This is because a task is not considered blocked
3156 while attempting to acquire the execution resource associated with
3157 a protected object. The acquisition of such a resource
3158 is rather considered part of the normal competition for execution
3159 resources between the various tasks that are ready.
3160 External calls that turn out to be on the same target
3161 object are considered potentially blocking, since they
3162 can deadlock the task indefinitely.
3163 @end(Reason)
3164
3165 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00305-01]}
3166 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0064-2]}
3167 @ChgAdded{Version=[2],Text=[@Chg{Version=[5],New=[The aspect Nonblocking can
3168 be specified True on the definition of a protected unit in order to reject
3169 most attempts to use potentially blocking operations
3170 within the protected unit (see @RefSecNum{Intertask Communication}). ],Old=[]}
3171 The @nt{pragma} Detect_Blocking may be used to
3172 ensure that @Chg{Version=[5],New=[any remaining],Old=[all]} executions of
3173 potentially blocking operations during a
3174 protected action raise Program_Error.
3175 See @RefSecNum{Pragma Detect_Blocking}.]}
3176 @begin{Discussion}
3177 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
3178 @ChgAdded{Version=[5],Text=[The deadlock case cannot be detected at
3179 compile-time, so pragma Detect_Blocking is needed to give it consistent
3180 behavior.]}
3181 @end{Discussion}
3182 @end{Notes}
3183
3184 @begin{Examples}
3185 @leading@i{Examples of protected subprogram calls
3186 (see @RefSecNum(Protected Units and Protected Objects)):}
3187 @begin{Example}
3188 Shared_Array.Set_Component(N, E);
3189 E := Shared_Array.Component(M);
3190 Control.Release;
3191 @end{Example}
3192
3193 @end{Examples}
3194
3195 @begin{DiffWord95}
3196 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00305-01]}
3197 @ChgAdded{Version=[2],Text=[Added a note pointing out the existence of
3198 @nt{pragma} Detect_Blocking. This pragma can be used to ensure portable
3199 (somewhat pessimistic) behavior of protected actions by converting the
3200 Bounded Error into a required check.]}
3201 @end{DiffWord95}
3202
3203 @begin{Extend2012}
3204 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0129-1]}
3205 @ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}
3206 @b<Corrigendum:> Aspect Exclusive_Functions is new. The term
3207 @ldquote@;exclusive protected operations@rdquote is new.]}
3208 @end{Extend2012}
3209
3210 @begin{DiffWord2012}
3211 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0064-2]}
3212 @ChgAdded{Version=[5],Text=[Moved the definition of potentially blocking
3213 operations to @RefSecNum{Intertask Communication}, so it could be
3214 integrated into the definition of the Nonblocking aspect.]}
3215
3216 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0247-1]}
3217 @ChgAdded{Version=[5],Text=[@b<Correction:> Added a separate bounded error
3218 for a subprogram containing a blocking operation, to keep compatibility with
3219 Ada 95 rules without requiring a correct implementation of pragma
3220 Detect_Blocking to do full program analysis.]}
3221 @end{DiffWord2012}
3222
3223
3224 @LabeledSubClause{Entries and Accept Statements}
3225
3226 @begin{Intro}
3227 @nt<Entry_declaration>s, with the corresponding @ntf<entry_bodies>
3228 or @nt<accept_statement>s,
3229 are used to define potentially queued operations on
3230 tasks and protected objects.
3231 @end{Intro}
3232
3233 @begin{Syntax}
3234 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00397-01]}
3235 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]}
3236 @Syn{lhs=<entry_declaration>,rhs="@Chg{Version=[2],New=<
3237 [@Syn2{overriding_indicator}]>,Old=[]}
3238 @key{entry} @Syn2{defining_identifier} [(@Syn2{discrete_subtype_definition})] @Syn2{parameter_profile}@Chg{Version=[3],New=<
3239 [@Syn2{aspect_specification}]>,Old=[]};"}
3240
3241
3242 @Syn{lhs=<accept_statement>,rhs="
3243 @key{accept} @SynI{entry_}@Syn2{direct_name} [(@Syn2{entry_index})] @Syn2{parameter_profile} [@key{do}
3244 @Syn2{handled_sequence_of_statements}
3245 @key{end} [@SynI{entry_}@Syn2{identifier}]];"}
3246 @begin{Reason}
3247 We cannot use @nt{defining_identifier} for @nt<accept_statement>s.
3248 Although an @nt{accept_statement} is sort of like a body, it can appear
3249 nested within a @nt{block_statement}, and therefore be hidden from
3250 its own entry by an outer homograph.
3251 @end{Reason}
3252
3253 @Syn{lhs=<entry_index>,rhs="@Syn2{expression}"}
3254
3255
3256 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0169-1]}
3257 @Syn{lhs=<entry_body>,rhs="
3258 @key{entry} @Syn2{defining_identifier} @Syn2{entry_body_formal_part}@Chg{Version=[5],New=<
3259 [@Syn2{aspect_specification}]
3260 >,Old=[]}@Syn2{entry_barrier} @key{is}
3261 @Syn2{declarative_part}
3262 @key{begin}
3263 @Syn2{handled_sequence_of_statements}
3264 @key{end} [@SynI{entry_}@Syn2{identifier}];"}
3265
3266 @begin{Discussion}
3267 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00397-01]}
3268 @ChgAdded{Version=[2],Text=[We don't allow an @nt{overriding_indicator} on
3269 an @nt{entry_body} because entries always implement procedures at the
3270 point of the type declaration; there is no late implementation. And we
3271 don't want to have to think about @nt{overriding_indicator}s on
3272 @nt{accept_statement}s.]}
3273 @end{Discussion}
3274
3275 @Syn{lhs=<entry_body_formal_part>,
3276 rhs="[(@Syn2{entry_index_specification})] @Syn2{parameter_profile}"}
3277
3278
3279 @Syn{lhs=<entry_barrier>,
3280 rhs="@key{when} @Syn2{condition}"}
3281
3282
3283 @Syn{lhs=<entry_index_specification>,
3284 rhs="@key{for} @Syn2{defining_identifier} @key{in} @Syn2{discrete_subtype_definition}"}
3285
3286 @begin{SyntaxText}
3287 If an @SynI{entry_}@nt{identifier} appears at the end of an
3288 @nt{accept_statement}, it shall repeat the @SynI{entry_}@!@nt<direct_@!name>.
3289 If an @SynI{entry_}@!@nt{identifier} appears at the end of an @nt{entry_@!body}, it shall repeat the
3290 @nt{defining_@!identifier}.
3291
3292 @Redundant[An @nt{entry_declaration} is allowed only in a protected or task
3293 declaration.]
3294 @begin(TheProof)
3295 This follows from the BNF.
3296 @end(TheProof)
3297
3298 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
3299 @ChgAdded{Version=[2],Text=[An @nt{overriding_indicator} is not allowed in an
3300 @nt{entry_declaration} that includes a @nt{discrete_subtype_definition}.]}
3301 @begin(Reason)
3302 @ChgRef{Version=[2],Kind=[Added]}
3303 @ChgAdded{Version=[2],Text=[An entry family can never implement something,
3304 so allowing an indicator is felt by the majority of the ARG to be redundant.]}
3305 @end(Reason)
3306 @end{SyntaxText}
3307 @end{Syntax}
3308
3309 @begin{Resolution}
3310
3311 @PDefn2{Term=[expected profile],
3312 Sec=(accept_statement @i{entry_}@nt<direct_name>)}
3313 In an @nt<accept_statement>,
3314 the expected profile for the @SynI{entry_}@nt<direct_name>
3315 is that of the @nt<entry_@!declaration>;
3316 @PDefn2{Term=[expected type],
3317 Sec=(entry_index)}
3318 the expected type for an @nt<entry_index> is that
3319 of the subtype defined by the @nt<discrete_@!subtype_@!definition>
3320 of the corresponding @nt<entry_@!declaration>.
3321
3322 Within the @nt<handled_sequence_of_statements> of an @nt<accept_statement>,
3323 if a @nt<selected_@!component> has a @nt<prefix> that denotes
3324 the corresponding @nt<entry_@!declaration>, then the
3325 entity denoted by the @nt<prefix> is the @nt<accept_@!statement>, and
3326 the @nt<selected_@!component> is interpreted as an expanded name
3327 (see @RefSecNum(Selected Components))@Redundant[; the @nt<selector_name>
3328 of the @nt<selected_@!component> has to be the @nt<identifier> for
3329 some formal parameter of the @nt<accept_@!statement>].
3330 @begin{TheProof}
3331 The only declarations that occur immediately within the
3332 declarative region of an @nt<accept_statement> are those
3333 for its formal parameters.
3334 @end{TheProof}
3335 @end{Resolution}
3336
3337 @begin{Legality}
3338
3339 An @nt<entry_declaration> in a task declaration shall not contain
3340 a specification for an access parameter (see @RefSecNum(Access Types)).
3341 @begin(Reason)
3342 @leading@;Access parameters for task entries would require a complex
3343 implementation. For example:
3344 @begin(Example)
3345 @key(task) T @key(is)
3346 @key(entry) E(Z : @key(access) Integer); --@RI{ Illegal!}
3347 @key(end) T;
3348
3349 @key(task body) T @key(is)
3350 @key(begin)
3351 @key(declare)
3352 @key(type) A @key(is access all) Integer;
3353 X : A;
3354 Int : @key(aliased) Integer;
3355 @key(task) Inner;
3356 @key(task body) Inner @key(is)
3357 @key(begin)
3358 T.E(Int'Access);
3359 @key(end) Inner;
3360 @key(begin)
3361 @key(accept) E(Z : @key(access) Integer) @key(do)
3362 X := A(Z); --@RI{ Accessibility_Check}
3363 @key(end) E;
3364 @key(end);
3365 @key(end) T;
3366 @end(Example)
3367
3368 Implementing the Accessibility_Check inside the @nt<accept_statement> for
3369 E is difficult, since one does not know whether the entry caller
3370 is calling from inside the immediately enclosing declare block or from
3371 outside it. This means that the lexical nesting level associated with
3372 the designated object is not sufficient to determine whether the
3373 Accessibility_Check should pass or fail.
3374
3375 Note that such problems do not arise with protected entries, because
3376 @ntf<entry_bodies> are always nested immediately within the
3377 @nt<protected_body>; they cannot be further nested as can
3378 @nt<accept_statement>s, nor can they be called from within the
3379 @nt<protected_body> (since no entry calls are permitted inside
3380 a @nt<protected_body>).
3381 @end(Reason)
3382
3383 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00397-01]}
3384 @ChgAdded{Version=[2],Type=[Leading],Text=[If an @nt{entry_declaration} has an
3385 @nt{overriding_indicator}, then at
3386 the point of the declaration:]}
3387 @begin{Itemize}
3388 @ChgRef{Version=[2],Kind=[Added]}
3389 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
3390 @key{overriding}, then the entry shall implement an inherited subprogram;]}
3391
3392 @ChgRef{Version=[2],Kind=[Added]}
3393 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
3394 @key{not overriding}, then the entry shall not implement any inherited
3395 subprogram.]}
3396
3397 @end{Itemize}
3398
3399 @ChgRef{Version=[2],Kind=[Added]}
3400 @ChgAdded{Version=[2],Text=[@PDefn{generic contract issue}In addition to the
3401 places where @LegalityTitle normally apply (see
3402 @RefSecNum{Generic Instantiation}), these rules also apply in the private part
3403 of an instance of a generic unit.]}
3404
3405 @begin{Discussion}
3406 @ChgRef{Version=[2],Kind=[AddedNormal]}
3407 @ChgAdded{Version=[2],Text=[These rules are subtly different than those for
3408 subprograms (see @RefSecNum{Overriding Indicators}) because there cannot be
3409 @lquotes@;late@rquotes inheritance of primitives from interfaces. Hidden
3410 (that is, private) interfaces are prohibited explicitly (see
3411 @RefSecNum{Private Types and Private Extensions}), as are hidden primitive
3412 operations (as private operations of public abstract types are prohibited
3413 @em see @RefSecNum{Abstract Types and Subprograms}).]}
3414 @end{Discussion}
3415
3416 For an @nt<accept_statement>,
3417 the innermost enclosing body shall be a @nt<task_body>,
3418 and the @i(entry_)@!@nt<direct_@!name> shall
3419 denote an @nt<entry_@!declaration> in the corresponding task declaration;
3420 the profile of the @nt{accept_@!statement} shall
3421 conform fully to that of the corresponding @nt<entry_@!declaration>.
3422 @Defn2{Term=[full conformance],Sec=(required)}
3423 An @nt<accept_@!statement> shall have a parenthesized @nt<entry_@!index> if
3424 and only if the corresponding @nt<entry_@!declaration> has a
3425 @nt<discrete_@!subtype_@!definition>.
3426
3427 An @nt<accept_statement> shall not be within another
3428 @nt{accept_statement} that corresponds to the same @nt<entry_@!declaration>,
3429 nor within an @nt<asynchronous_@!select> inner to
3430 the enclosing @nt<task_body>.
3431 @begin(Reason)
3432 @nt<Accept_statement>s are required to be immediately within
3433 the enclosing @nt<task_body> (as opposed to being in a nested
3434 subprogram) to ensure that a nested task does not
3435 attempt to accept the entry of its enclosing task. We considered
3436 relaxing this restriction, either by making the check a run-time
3437 check, or by allowing a nested task to accept an entry of its
3438 enclosing task. However, neither change seemed to provide sufficient
3439 benefit to justify the additional implementation burden.
3440
3441 Nested @nt<accept_statement>s for the same entry (or entry family)
3442 are prohibited to ensure that there is no ambiguity in the
3443 resolution of an expanded name for a formal parameter of the
3444 entry. This could be relaxed by allowing the inner
3445 one to hide the outer one from all visibility, but again the
3446 small added benefit didn't seem to justify making the change for Ada 95.
3447
3448 @nt<Accept_statement>s are not permitted within @nt<asynchronous_select>
3449 statements to simplify the semantics and implementation:
3450 an @nt<accept_statement> in an @nt<abortable_part> could result
3451 in Tasking_Error being propagated from an entry call even though
3452 the target task was still callable; implementations that use
3453 multiple tasks implicitly to implement an @nt<asynchronous_select>
3454 might have trouble supporting "up-level" accepts.
3455 Furthermore, if @nt<accept_statement>s were permitted in
3456 the @nt<abortable_part>, a task could call its own
3457 entry and then accept it in the @nt<abortable_part>, leading
3458 to rather unusual and possibly difficult-to-specify semantics.
3459 @end(Reason)
3460
3461 @PDefn2{Term=[requires a completion], Sec=(protected @nt{entry_declaration})}
3462 An @nt{entry_declaration} of a protected unit requires
3463 a completion@redundant[, which shall be an @nt{entry_body},]
3464 @PDefn2{Term=[only as a completion], Sec=(@nt<entry_body>)}
3465 and every @nt<entry_@!body> shall be the completion
3466 of an @nt<entry_@!declaration> of a protected unit.
3467 @PDefn2{Term=[completion legality], Sec=(@nt<entry_body>)}
3468 The profile of the @nt<entry_@!body> shall conform fully to that
3469 of the corresponding declaration.
3470 @Defn2{Term=[full conformance],Sec=(required)}
3471 @begin{Ramification}
3472 An @nt<entry_declaration>, unlike a @nt<subprogram_declaration>,
3473 cannot be completed with a @nt<renaming_@!declaration>.
3474 @end{Ramification}
3475 @begin(Honest)
3476 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
3477 @Chg{Version=[3],New=[If],Old=[The completion
3478 can be a @nt{pragma} Import, if]} the implementation supports
3479 it@Chg{Version=[3],New=[, the entry body can be imported
3480 (using aspect Import, see @RefSecNum{Interfacing Aspects}),
3481 in which case no explicit @nt{entry_body} is allowed],Old=[]}.
3482 @end(Honest)
3483 @begin{Discussion}
3484 The above applies only to protected entries,
3485 which are the only ones completed with @ntf{entry_bodies}.
3486 Task entries have corresponding @nt{accept_statement}s
3487 instead of having @ntf{entry_bodies}, and
3488 we do not consider an @nt{accept_statement} to be a @lquotes@;completion,@rquotes@;
3489 because a task @nt{entry_declaration} is allowed to have zero, one, or more
3490 than one corresponding @nt{accept_statement}s.
3491 @end{Discussion}
3492
3493 An @nt{entry_body_formal_part} shall have an @nt{entry_@!index_@!specification}
3494 if and only if the corresponding @nt{entry_@!declaration} has
3495 a @nt<discrete_@!subtype_@!definition>.
3496 In this case, the @nt<discrete_@!subtype_@!definition>s of the
3497 @nt<entry_@!declaration> and the @nt<entry_@!index_@!specification>
3498 shall fully conform to one another (see @RefSecNum(Conformance Rules)).
3499 @Defn2{Term=[full conformance],Sec=(required)}
3500
3501 A name that denotes a formal parameter of an @nt<entry_body> is not
3502 allowed within the @nt<entry_barrier> of the @nt<entry_body>.
3503
3504 @end{Legality}
3505
3506 @begin{StaticSem}
3507 The parameter modes defined for parameters in the @nt<parameter_profile>
3508 of an @nt{entry_declaration}
3509 are the same as for a @nt<subprogram_declaration> and have
3510 the same meaning (see @RefSecNum(Formal Parameter Modes)).
3511 @begin{Discussion}
3512 Note that access parameters are not allowed for task entries (see above).
3513 @end{Discussion}
3514
3515 @Defn2{Term=[family], Sec=(entry)}
3516 @Defn{entry family}
3517 @Defn{entry index subtype}
3518 An @nt<entry_declaration> with a @nt<discrete_subtype_definition>
3519 (see @RefSecNum(Array Types)) declares a @i(family) of distinct
3520 entries having the same profile, with one such entry for each
3521 value of the @i(entry index subtype) defined
3522 by the @nt<discrete_@!subtype_@!definition>.
3523 @Redundant[A name for an entry of a family takes the form of
3524 an @nt<indexed_component>, where the @nt<prefix> denotes
3525 the @nt<entry_declaration> for the family, and the index value
3526 identifies the entry within the family.]
3527 @Defn{single entry}
3528 @Defn2{Term=[entry], Sec=(single)}
3529 The term @i(single entry) is used to refer to any entry other
3530 than an entry of an entry family.
3531
3532 In the @nt<entry_body> for an entry family,
3533 the @nt<entry_index_specification> declares a named constant
3534 whose subtype is the entry index subtype defined by the
3535 corresponding @nt<entry_declaration>;
3536 @Defn{named entry index}
3537 the value of the @i(named entry index) identifies
3538 which entry of the family was called.
3539 @begin{Ramification}
3540 The @nt<discrete_subtype_definition> of the @nt<entry_index_specification>
3541 is not elaborated; the subtype of the named constant declared
3542 is defined by the @nt<discrete_subtype_definition> of the corresponding
3543 @nt<entry_declaration>, which is elaborated, either when the
3544 type is declared, or when the object is created, if its constraint
3545 is per-object.
3546 @end{Ramification}
3547
3548 @end{StaticSem}
3549
3550 @begin{RunTime}
3551
3552 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
3553 @PDefn2{Term=[elaboration], Sec=(entry_declaration)}
3554 @Chg{New=[The elaboration of an @nt<entry_declaration> for an entry family
3555 consists of the elaboration of the @nt<discrete_@!subtype_@!definition>, as
3556 described in @RefSecNum(Record Types).],
3557 Old=[For the elaboration of an @nt<entry_@!declaration> for an
3558 entry family, if the
3559 @nt{discrete_@!subtype_@!definition} contains no per-object expressions
3560 (see @RefSecNum(Record Types)), then the @nt<discrete_@!subtype_@!definition>
3561 is elaborated. Otherwise, the elaboration of the
3562 @nt<entry_@!declaration> consists of the evaluation of any
3563 expression of the @nt<discrete_@!subtype_@!definition>
3564 that is not a per-object expression (or part of one).]}
3565 The elaboration of an @nt<entry_@!declaration> for a single entry
3566 has no effect.
3567 @begin{Discussion}
3568 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
3569 The elaboration of the declaration of a protected subprogram has
3570 no effect, as specified in @Chg{Version=[3],New=[subclause],Old=[clause]}
3571 @RefSecNum(Subprogram Declarations).
3572 The default initialization of an object of a task or protected
3573 type is covered in @RefSecNum(Object Declarations).
3574 @end{Discussion}
3575
3576 @Redundant[The actions to be performed when
3577 an entry is called are specified by the
3578 corresponding @nt{accept_@!statement}s (if any) for an entry of a task unit,
3579 and by the corresponding @nt<entry_@!body> for an entry of a protected unit.]
3580
3581 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0193-1]}
3582 @ChgAdded{Version=[5],Text=[@Defn{rendezvous}
3583 The interaction between a task that calls an entry and an
3584 accepting task is called a @i(rendezvous).]}
3585
3586 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0193-1]}
3587 @PDefn2{Term=[execution], Sec=(accept_statement)}
3588 For the execution of an @nt{accept_statement}, the @nt<entry_index>, if
3589 any, is first evaluated and converted to the entry index subtype;
3590 this index value identifies which entry of the family is to be accepted.
3591 @PDefn2{Term=[implicit subtype conversion],Sec=(entry index)}
3592 @PDefn2{Term=[blocked], Sec=(on an @nt<accept_statement>)}
3593 @Defn2{Term=[selection], Sec=(of an entry caller)}
3594 Further execution of the @nt<accept_statement> is then blocked
3595 until a caller of the corresponding entry is selected
3596 (see @RefSecNum(Entry Calls)), whereupon
3597 the @nt<handled_sequence_of_statements>, if any, of the @nt<accept_statement>
3598 is executed, with the formal parameters associated with the
3599 corresponding actual parameters of the selected entry call.
3600 @Chg{Version=[5],New=[Execution of the rendezvous consists of the
3601 execution ],Old=[]}of the @nt{handled_sequence_of_statements},
3602 @Chg{Version=[5],New=[ performance of any postcondition or type
3603 invariant checks associated with the entry, and any initialization or
3604 finalization associated with these checks, as described in
3605 @RefSecNum{Preconditions and Postconditions} and @RefSecNum{Type Invariants}.
3606 After execution of the rendezvous, ],Old=[]}the @nt<accept_statement>
3607 completes and is left. @Chg{Version=[5],New=[@Redundant[The two tasks then
3608 proceed independently.] ],Old=[]}When an exception is propagated from the
3609 @nt{handled_sequence_of_statements} of an @nt{accept_statement},
3610 the same exception is also raised by the execution of the corresponding
3611 @nt{entry_call_statement}.
3612 @begin{Ramification}
3613 This is in addition to propagating it to the construct
3614 containing the @nt{accept_statement}.
3615 In other words, for a rendezvous, the raising splits in two,
3616 and continues concurrently in both tasks.
3617
3618 The caller gets a new occurrence;
3619 this isn't considered propagation.
3620
3621 Note that we say @lquotes@;propagated from the
3622 @nt{handled_sequence_of_statements} of an @nt{accept_statement}@rquotes@;,
3623 not @lquotes@;propagated from an @nt{accept_statement}.@rquotes@;
3624 The latter would be wrong @em we don't want exceptions propagated by
3625 the @nt<entry_index> to be sent to the caller (there is none yet!).
3626
3627 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0193-1]}
3628 @ChgAdded{Version=[5],Text=[Execution of the rendezvous does not include
3629 any checks associated with parameter copy back or any
3630 post-call subtype predicate check for a parameter which is
3631 passed by reference. These checks are performed by
3632 the caller after the execution of the rendezvous.]}
3633 @end{Ramification}
3634
3635 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0193-1]}
3636 @ChgDeleted{Version=[5],Text=[@Defn{rendezvous}
3637 The above interaction between a calling task and an
3638 accepting task is called a @i(rendezvous).
3639 @Redundant[After a rendezvous, the two tasks continue
3640 their execution independently.]]}
3641
3642 @Redundant[An @nt<entry_body> is executed when the @nt<condition> of the
3643 @nt<entry_barrier> evaluates to True and a caller of the corresponding
3644 single entry, or entry of the corresponding entry family,
3645 has been selected (see @RefSecNum(Entry Calls)).]
3646 @PDefn2{Term=[execution], Sec=(entry_body)}
3647 For the execution of the @nt<entry_@!body>,
3648 the @nt<declarative_@!part> of the @nt<entry_@!body> is elaborated,
3649 and the @nt<handled_@!sequence_of_@!statements>
3650 of the body is executed, as for the execution
3651 of a @nt<subprogram_body>. The value of the named entry index, if any,
3652 is determined by the value of the entry index specified in the
3653 @i(entry_)@nt<name> of the selected entry call (or intermediate
3654 @nt<requeue_@!statement> @em see @RefSecNum(Requeue Statements)).
3655 @begin(Honest)
3656 If the entry had been renamed as a subprogram,
3657 and the call was a @nt<procedure_call_statement> using
3658 the name declared by the renaming, the entry index (if any) comes from
3659 the entry @nt<name> specified in the
3660 @nt<subprogram_renaming_declaration>.
3661 @end(Honest)
3662
3663 @end{RunTime}
3664
3665 @begin{Notes}
3666
3667 A task entry has corresponding accept_statements (zero or more),
3668 whereas a protected entry has a corresponding entry_body (exactly
3669 one).
3670
3671 A consequence of the rule regarding the allowed placements of
3672 @nt{accept_statement}s is that a task can execute @nt{accept_statement}s
3673 only for its own entries.
3674
3675 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
3676 A @Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]}
3677 (see @RefSecNum(Return Statements))
3678 or a @nt<requeue_statement> (see @RefSecNum(Requeue Statements))
3679 may be used to complete the execution of
3680 an @nt<accept_statement> or an @nt<entry_body>.
3681 @begin{Ramification}
3682 An @nt<accept_statement> need not have a @nt<handled_sequence_of_statements>
3683 even if the corresponding entry has parameters. Equally, it can have
3684 a @nt<handled_sequence_of_statements> even if the corresponding entry
3685 has no parameters.
3686 @end{Ramification}
3687 @begin{Ramification}
3688 A single entry overloads a subprogram, an enumeration literal, or another
3689 single entry if they have the same @nt{defining_identifier}. Overloading is
3690 not allowed for entry family names.
3691 A single entry or an entry of an entry family
3692 can be renamed as a procedure as explained in
3693 @RefSecNum{Subprogram Renaming Declarations}.
3694 @end{Ramification}
3695
3696 The @nt<condition> in the @nt{entry_barrier} may reference
3697 anything visible except the formal parameters of the entry.
3698 This
3699 includes the entry index (if any), the components (including discriminants) of
3700 the protected object, the Count attribute of an entry of that protected object,
3701 and data global to the protected unit.
3702
3703 @NoPrefix@;The restriction against referencing the formal parameters within an
3704 @nt{entry_barrier} ensures that all calls of the same entry see
3705 the same barrier value.
3706 If it is necessary to look at the parameters of an entry
3707 call before deciding whether to handle it, the @nt<entry_barrier>
3708 can be @lquotes@;@key(when) True@rquotes@; and the caller can
3709 be requeued (on some private entry)
3710 when its parameters indicate that it cannot be handled immediately.
3711 @end{Notes}
3712
3713 @begin{Examples}
3714 @leading@keepnext@i{Examples of entry declarations:}
3715 @begin{Example}
3716 @key(entry) Read(V : @key(out) Item);
3717 @key(entry) Seize;
3718 @key(entry) Request(Level)(D : Item); --@RI[ a family of entries]
3719 @end{Example}
3720
3721 @begin{WideAbove}
3722 @leading@keepnext@i{Examples of accept statements:}
3723 @end{WideAbove}
3724 @begin{Example}
3725 @key(accept) Shut_Down;
3726
3727 @key(accept) Read(V : @key(out) Item) @key(do)
3728 V := Local_Item;
3729 @key(end) Read;
3730
3731 @key(accept) Request(Low)(D : Item) @key(do)
3732 ...
3733 @key(end) Request;
3734 @end{Example}
3735
3736 @end{Examples}
3737
3738 @begin{Extend83}
3739 @Defn{extensions to Ada 83}
3740 The syntax rule for @nt{entry_body} is new.
3741
3742 @nt{Accept_statement}s can now have @nt{exception_handler}s.
3743 @end{Extend83}
3744
3745 @begin{DiffWord95}
3746 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
3747 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified the elaboration of
3748 per-object constraints.]}
3749
3750 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00397-01]}
3751 @ChgAdded{Version=[2],Text=[@nt{Overriding_indicator}s can be used on
3752 entries; this is only useful when a task or protected type inherits
3753 from an interface.]}
3754 @end{DiffWord95}
3755
3756 @begin{Extend2005}
3757 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]}
3758 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
3759 An optional @nt{aspect_specification} can be used in an @nt{entry_declaration}.
3760 This is described in @RefSecNum{Aspect Specifications}.]}
3761 @end{Extend2005}
3762
3763 @begin{Extend2012}
3764 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0169-1]}
3765 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
3766 @b<Correction:> An optional @nt{aspect_specification} can be used in an
3767 @nt{entry_body}. All other kinds of bodies allow (only) implementation-defined
3768 aspects, we need to be consistent.]}
3769 @end{Extend2012}
3770
3771 @begin{Diffword2012}
3772 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0193-1]}
3773 @ChgAdded{Version=[5],Text=[@b<Correction:> Clarified that postcondition and
3774 invariant checks are clearly part of the rendezvous for an entry call.
3775 @RefSecNum{Preconditions and Postconditions} already said this, so the
3776 intent was clear and this is not an inconsistency.]}
3777 @end{Diffword2012}
3778
3779
3780 @LabeledSubClause{Entry Calls}
3781
3782 @begin{Intro}
3783 @Defn{entry call}
3784 @Redundant[An @nt<entry_call_statement> (an @i(entry call)) can appear in
3785 various contexts.]
3786 @Defn{simple entry call}
3787 @Defn2{Term={entry call}, Sec=(simple)}
3788 A @i(simple) entry call is a stand-alone statement that
3789 represents an unconditional call on an entry of a target
3790 task or a protected object.
3791 @Redundant[Entry calls can also appear
3792 as part of @nt<select_statement>s
3793 (see @RefSecNum(Select Statements)).]
3794 @end{Intro}
3795
3796 @begin{Syntax}
3797 @Syn{lhs=<entry_call_statement>,rhs="@SynI{entry_}@Syn2{name} [@Syn2{actual_parameter_part}];"}
3798 @end{Syntax}
3799
3800 @begin{Resolution}
3801 The @i(entry_)@nt<name> given in an @nt<entry_call_statement> shall resolve
3802 to denote an entry. The rules for parameter
3803 associations are the same as for subprogram calls (see @RefSecNum(Subprogram Calls)
3804 and @RefSecNum(Parameter Associations)).
3805 @end{Resolution}
3806
3807 @begin{StaticSem}
3808 @Redundant[The @i(entry_)@nt<name> of an @nt<entry_call_statement> specifies
3809 (explicitly or implicitly) the target object of the call,
3810 the entry or entry family, and the entry index, if any
3811 (see @RefSecNum(Intertask Communication)).]
3812 @end{StaticSem}
3813
3814 @begin{RunTime}
3815 @leading@Defn{open entry}
3816 @Defn2{Term=[entry], Sec=(open)}
3817 @Defn{closed entry}
3818 @Defn2{Term=[entry], Sec=(closed)}
3819 Under certain circumstances (detailed below), an entry of a task
3820 or protected
3821 object is checked to see whether it is @i(open) or @i(closed):
3822 @begin(Itemize)
3823 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3824 @Defn2{Term=[open entry], Sec=(of a task)}
3825 @Defn2{Term=[closed entry], Sec=(of a task)}
3826 An entry of a task is open if the task
3827 is blocked on an @nt<accept_statement>
3828 that corresponds to the entry (see @RefSecNum(Entries and Accept Statements)),
3829 or on a @nt<selective_accept>
3830 (see @RefSecNum(Selective Accept)) with an open
3831 @nt<accept_alternative> that corresponds to the entry;
3832 otherwise@Chg{Version=[3],New=[,],Old=[]} it is closed.
3833
3834 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3835 @Defn2{Term=[open entry], Sec=(of a protected object)}
3836 @Defn2{Term=[closed entry], Sec=(of a protected object)}
3837 An entry of a protected object is open if
3838 the @nt<condition> of the @nt<entry_barrier> of the
3839 corresponding @nt<entry_body> evaluates to True;
3840 otherwise@Chg{Version=[3],New=[,],Old=[]} it is closed.
3841 @Defn2{Term=[Program_Error],Sec=(raised by barrier failure)}
3842 If the evaluation of the @nt<condition> propagates an exception, the
3843 exception Program_Error is propagated
3844 to all current callers of all entries of the protected object.
3845 @begin(Reason)
3846 An exception during barrier evaluation is considered essentially
3847 a fatal error. All current entry callers are notified with a Program_Error.
3848 In a fault-tolerant system, a protected object might provide a Reset
3849 protected procedure, or equivalent, to support attempts to restore such
3850 a "broken" protected object to a reasonable state.
3851 @end(Reason)
3852 @end(Itemize)
3853 @begin(Discussion)
3854 Note that the definition of when a task entry is open is
3855 based on the state of the (accepting) task, whereas the
3856 "openness" of a protected entry is defined only
3857 when it is explicitly checked, since the barrier expression needs to
3858 be evaluated. Implementation permissions are given (below) to
3859 allow implementations to evaluate the barrier expression more or
3860 less often than it is checked, but the basic semantic model presumes
3861 it is evaluated at the times when it is checked.
3862 @end(Discussion)
3863
3864 @leading@PDefn2{Term=[execution], Sec=(entry_call_statement)}
3865 For the execution of an @nt{entry_call_statement},
3866 evaluation of the @nt<name>
3867 and of the parameter associations
3868 is as for a subprogram call (see @RefSecNum{Subprogram Calls}).
3869 @Defn2{Term=[issue], Sec=(an entry call)}
3870 The entry call is then @i(issued):
3871 For a call on an entry of a protected object, a new protected
3872 action is started on the object (see @RefSecNum(Protected Subprograms and Protected Actions)).
3873 The named entry is checked to see if it is open;
3874 @Defn2{Term=[select an entry call], Sec=(immediately)}
3875 if open, the entry call is said to be @i(selected immediately),
3876 and the execution of the call proceeds as follows:
3877 @begin(Itemize)
3878 For a call on an open entry of a task, the accepting task becomes ready and
3879 continues the execution of the corresponding @nt<accept_statement>
3880 (see @RefSecNum(Entries and Accept Statements)).
3881
3882 For a call on an open entry of a protected object, the corresponding
3883 @nt<entry_body> is executed (see @RefSecNum(Entries and Accept Statements))
3884 as part of the protected action.
3885 @end(Itemize)
3886
3887 If the @nt<accept_statement> or @nt<entry_body> completes other than
3888 by a requeue (see @RefSecNum(Requeue Statements)), return is made to the
3889 caller (after servicing the entry queues @em see below);
3890 any necessary assigning back
3891 of formal to actual parameters occurs,
3892 as for a subprogram call (see @RefSecNum(Parameter Associations));
3893 such assignments take
3894 place outside of any protected action.
3895 @begin(Ramification)
3896 The return to the caller will generally not occur until
3897 the protected action completes, unless some other thread of
3898 control is given the job of completing the protected action
3899 and releasing the associated execution resource.
3900 @end(Ramification)
3901
3902 If the named entry is closed, the entry call is added to an @i(entry queue)
3903 (as part of the protected action, for a call on a protected entry),
3904 and the call remains queued until it is selected or cancelled;
3905 @Defn{entry queue}
3906 there is a separate (logical) entry queue for each entry of a
3907 given task or protected object
3908 @Redundant[(including each entry of an entry family)].
3909
3910 @Leading@Defn2{Term=[service], Sec=(an entry queue)}
3911 @Defn2{Term=[select an entry call], Sec=(from an entry queue)}
3912 When a queued call is @i{selected}, it is removed from its entry queue.
3913 Selecting a queued call from a particular entry queue is
3914 called @i{servicing} the entry queue.
3915 An entry with queued calls can be serviced under
3916 the following circumstances:
3917 @begin(Itemize)
3918 When the associated task reaches a corresponding @nt<accept_statement>, or
3919 a @nt<selective_accept> with a corresponding
3920 open @nt<accept_alternative>;
3921
3922 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0129-1]}
3923 If after performing, as part of a protected action on the
3924 associated protected object, an
3925 @Chg{Version=[4],New=[exclusive protected ],Old=[]}operation
3926 on the object@Chg{Version=[4],New=[],Old=[ other than
3927 a call on a protected function]},
3928 the entry is checked and found to be open.
3929 @end(Itemize)
3930
3931 @Defn2{Term=[select an entry call], Sec=(from an entry queue)}
3932 If there is at least one call on a queue corresponding to
3933 an open entry, then one such call is selected according to the
3934 @i(entry queuing policy) in effect (see below), and the
3935 corresponding @nt<accept_statement> or @nt<entry_body> is
3936 executed as above for an entry call that is selected immediately.
3937
3938 @Defn{entry queuing policy}
3939 The entry queuing policy controls selection among queued calls
3940 both for task and protected entry queues.
3941 @Defn{default entry queuing policy}
3942 @Defn2{Term=[entry queuing policy], Sec=(default policy)}
3943 The default entry queuing policy is to select calls on a given entry
3944 queue in order of arrival. If calls from two or more queues are
3945 simultaneously eligible for selection, the default entry queuing policy
3946 does not specify which queue is serviced first.
3947 Other entry queuing policies can be specified by @nt{pragma}s
3948 (see @RefSecNum(Entry Queuing Policies)).
3949
3950 For a protected object, the above servicing of entry queues continues
3951 until there are no open entries with queued calls, at which point
3952 the protected action completes.
3953 @begin(Discussion)
3954 While servicing the entry queues of a protected object, no new calls
3955 can be added to any entry queue of the object,
3956 except due to an internal requeue (see @RefSecNum(Requeue Statements)).
3957 This is because the first step of a call on a protected entry
3958 is to start a new protected action, which implies acquiring
3959 (for exclusive read-write access)
3960 the execution resource associated with the protected object, which cannot
3961 be done while another protected action is already in progress.
3962 @end(Discussion)
3963
3964 @PDefn2{Term=[blocked], Sec=(during an entry call)}
3965 For an entry call that is added to a queue,
3966 and that is not the @nt<triggering_statement> of an
3967 @nt<asynchronous_@!select>
3968 (see @RefSecNum{Asynchronous Transfer of Control}),
3969 the calling task is blocked until the call is cancelled,
3970 or the call is selected and a corresponding @nt<accept_statement>
3971 or @nt<entry_body> completes without requeuing.
3972 In addition, the calling task is blocked during a rendezvous.
3973
3974 @begin{Ramification}
3975
3976 For a call on a protected entry,
3977 the caller is not blocked if the call is selected immediately,
3978 unless a requeue causes the call to be queued.
3979
3980 @end{Ramification}
3981
3982 @Defn2{Term=[cancellation], Sec=(of an entry call)}
3983 An attempt can be made to cancel an entry call upon an abort
3984 (see @RefSecNum(Abort of a Task - Abort of a Sequence of Statements))
3985 and as part of certain forms of @nt<select_statement>
3986 (see @RefSecNum(Timed Entry Calls),
3987 @RefSecNum(Conditional Entry Calls), and
3988 @RefSecNum(Asynchronous Transfer of Control)).
3989 The cancellation does not take place until
3990 a point (if any) when the call is on some entry queue,
3991 and not protected from cancellation as part of a requeue
3992 (see @RefSecNum(Requeue Statements)); at such a point, the
3993 call is removed from the entry queue and the call completes due
3994 to the cancellation.
3995 The cancellation of a call on an entry of a protected object
3996 is a protected action@Redundant[, and as such cannot take place
3997 while any other protected action is occurring on the protected object.
3998 Like any protected action, it includes servicing of the entry queues
3999 (in case some entry barrier depends on a Count attribute).]
4000 @begin(ImplNote)
4001 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4002 In the case of an attempted cancellation due to abort,
4003 this removal might have to be performed by the calling task
4004 itself if the ceiling priority of the protected object
4005 is lower than the @Chg{Version=[2],New=[priority of the ],Old=[]}task
4006 initiating the abort.
4007 @end(ImplNote)
4008
4009 @IndexCheck{Tasking_Check}
4010 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of runtime check)}
4011 A call on an entry of a task that has already completed its execution
4012 raises the exception Tasking_Error at the point of the call;
4013 similarly, this exception is raised at the point of the call if the
4014 called task completes its execution or becomes abnormal before accepting
4015 the call or completing the rendezvous
4016 (see @RefSecNum(Abort of a Task - Abort of a Sequence of Statements)).
4017 This applies equally to a simple entry call and to an entry call as part
4018 of a @nt<select_statement>.
4019
4020 @end{RunTime}
4021
4022 @begin{ImplPerm}
4023
4024 An implementation may perform the sequence of steps of a protected action
4025 using any thread of control; it need not be that of the task
4026 that started the protected action.
4027 If an @nt<entry_body> completes without requeuing, then the
4028 corresponding calling task may be made ready
4029 without waiting for the entire protected action to complete.
4030 @begin(Reason)
4031 These permissions are intended to allow flexibility for implementations
4032 on multiprocessors. On a monoprocessor, which thread of control executes
4033 the protected action is essentially invisible, since the thread is
4034 not abortable in any case, and the "current_task" function is not
4035 guaranteed to work during a protected action
4036 (see @Chg{Version=[2],New=[@RefSecNum(The Package Task_Identification)],
4037 Old=[@RefSecNum(Task Information)]}).
4038 @end(Reason)
4039
4040 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0129-1]}
4041 When the entry of a protected object is checked to see whether it
4042 is open, the implementation need not reevaluate
4043 the @nt<condition> of the corresponding @nt<entry_barrier>
4044 if no variable or attribute referenced by
4045 the @nt<condition> (directly or indirectly)
4046 has been altered by the execution (or cancellation) of a
4047 @Chg{Version=[4],New=[],Old=[protected procedure or entry ]}call
4048 @Chg{Version=[4],New=[to an exclusive protected operation of],Old=[on]} the
4049 object since the @nt<condition> was last evaluated.
4050 @begin(Ramification)
4051 @ChgRef{Version=[4],Kind=[Revised]}
4052 Changes to variables referenced by an entry barrier that
4053 result from actions outside of a
4054 @Chg{Version=[4],New=[],Old=[protected procedure or entry ]}call
4055 @Chg{Version=[4],New=[to an exclusive protected operation of],Old=[on]} the
4056 protected object need not be "noticed." For example, if
4057 a global variable is referenced by an entry barrier, it should not
4058 be altered (except as part of a protected action on the object) any
4059 time after the barrier is first evaluated.
4060 In other words, globals can be used to "parameterize" a protected object,
4061 but they cannot reliably be used to control it after the first
4062 use of the protected object.
4063 @end(Ramification)
4064 @begin{ImplNote}
4065 Note that even if a global variable is volatile,
4066 the implementation need only reevaluate a barrier if the
4067 global is updated during a protected action on the protected object.
4068 This ensures that an entry-open bit-vector implementation
4069 approach is possible, where the bit-vector is computed at
4070 the end of a protected action, rather than upon each entry call.
4071 @end{ImplNote}
4072
4073 An implementation may evaluate the @nt<condition>s of all @nt<entry_barrier>s
4074 of a given protected object any time any entry of the object
4075 is checked to see if it is open.
4076 @begin(Ramification)
4077 In other words, any side effects of evaluating an entry barrier
4078 should be innocuous, since an entry barrier might be evaluated more
4079 or less often than is implied by the "official" dynamic semantics.
4080 @end(Ramification)
4081 @begin(ImplNote)
4082 It is anticipated that when the number of entries is known to be small,
4083 all barriers will be evaluated any time one of them needs to be,
4084 to produce an "entry-open bit-vector." The appropriate bit will
4085 be tested when the entry is called, and only if the bit is false
4086 will a check be made to see whether the bit-vector might need to
4087 be recomputed. This should allow an implementation to maximize
4088 the performance of a call on an open entry, which seems like the
4089 most important case.
4090
4091 In addition to the entry-open bit-vector, an "is-valid"
4092 bit is needed per object, which indicates whether the current
4093 bit-vector setting is valid.
4094 A "depends-on-Count-attribute" bit is needed per type.
4095 The "is-valid" bit is set to false
4096 (as are all the bits of the bit-vector) when the protected object is first
4097 created, as well as any time an exception is propagated from computing
4098 the bit-vector. Is-valid would also be set false any time the
4099 Count is changed and
4100 "depends-on-Count-attribute" is true for the type, or a
4101 protected procedure or entry returns indicating it might have updated a
4102 variable referenced in some barrier.
4103
4104 A single procedure can be compiled to evaluate all of the barriers,
4105 set the entry-open bit-vector accordingly, and set the is-valid bit to true.
4106 It could have a "when others" handler to set them all false,
4107 and call a routine to propagate Program_Error to all queued callers.
4108
4109 For protected types where the number of entries is not known to be
4110 small, it makes more sense to evaluate a barrier only when the
4111 corresponding entry is checked to see if it is open. It isn't worth
4112 saving the state of the entry between checks, because of the space
4113 that would be required. Furthermore, the entry queues probably want
4114 to take up space only when there is actually a caller on them, so
4115 rather than an array of all entry queues, a linked list of nonempty
4116 entry queues make the most sense in this case, with the first caller
4117 on each entry queue acting as the queue header.
4118 @end(ImplNote)
4119
4120 When an attempt is made to cancel an entry call, the implementation
4121 need not make the attempt using the thread of control of the
4122 task (or interrupt) that initiated the cancellation; in particular,
4123 it may use the thread of control of the caller itself to attempt the
4124 cancellation, even if this might allow the entry call to be
4125 selected in the interim.
4126 @begin{Reason}
4127 Because cancellation of a protected entry call is a protected
4128 action (which helps make the Count attribute of a protected
4129 entry meaningful), it might
4130 not be practical to attempt the cancellation from the thread
4131 of control that initiated the cancellation. For example,
4132 if the cancellation is due to the expiration of a delay,
4133 it is unlikely that the handler of the timer interrupt could
4134 perform the necessary protected action itself (due to being
4135 on the interrupt level). Similarly, if the cancellation
4136 is due to an abort, it is possible that the task initiating
4137 the abort has a priority higher than the ceiling priority of the
4138 protected object (for implementations that support ceiling priorities).
4139 Similar considerations could apply in a multiprocessor situation.
4140 @end{Reason}
4141
4142 @end{ImplPerm}
4143
4144 @begin{Notes}
4145
4146 If an exception is raised during the execution of an @nt{entry_body}, it is
4147 propagated to the corresponding caller (see @RefSecNum(Exception Handling)).
4148
4149 For a call on a protected entry, the entry is checked to see if
4150 it is open prior to queuing the call, and again thereafter
4151 if its Count attribute (see @RefSecNum{Task and Entry Attributes})
4152 is referenced in some entry barrier.
4153 @begin(Ramification)
4154 Given this, extra care is required if
4155 a reference to the Count attribute of an entry
4156 appears in the entry's own barrier.
4157 @end(Ramification)
4158 @begin(Reason)
4159 An entry is checked to see if it is open prior to queuing
4160 to maximize the performance of a call on an open entry.
4161 @end(Reason)
4162
4163 In addition to simple entry calls,
4164 the language permits timed, conditional, and asynchronous entry calls
4165 (see @RefSecNum(Timed Entry Calls), @RefSecNum(Conditional Entry Calls),
4166 and see @RefSecNum(Asynchronous Transfer of Control)).
4167 @begin{Ramification}
4168 A task can call its own entries, but
4169 the task will deadlock if the call is a simple entry call.
4170 @end{Ramification}
4171
4172 The @nt<condition> of an @nt<entry_barrier> is allowed to be evaluated by
4173 an implementation more often than strictly necessary, even if the
4174 evaluation might have side effects. On the other hand, an implementation
4175 need not reevaluate the @nt<condition> if nothing it references was
4176 updated by an intervening protected action on the protected object,
4177 even if the @nt<condition> references some global variable that might
4178 have been updated by an action performed from outside of a protected action.
4179 @end{Notes}
4180
4181 @begin{Examples}
4182 @leading@keepnext@i{Examples of entry calls:}
4183 @begin{Example}
4184 Agent.Shut_Down; --@RI[ see @RefSecNum(Task Units and Task Objects)]
4185 Parser.Next_Lexeme(E); --@RI[ see @RefSecNum(Task Units and Task Objects)]
4186 Pool(5).Read(Next_Char); --@RI[ see @RefSecNum(Task Units and Task Objects)]
4187 Controller.Request(Low)(Some_Item); --@RI[ see @RefSecNum(Task Units and Task Objects)]
4188 Flags(3).Seize; --@RI[ see @RefSecNum(Protected Units and Protected Objects)]
4189 @end{Example}
4190 @end{Examples}
4191
4192 @begin{DiffWord2012}
4193 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0129-1]}
4194 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Revised wording to talk
4195 about @ldquote@;exclusive protected operations@rdquote
4196 (see @RefSecNum{Protected Subprograms and Protected Actions}).]}
4197 @end{DiffWord2012}
4198
4199
4200 @LabeledSubClause{Requeue Statements}
4201
4202 @begin{Intro}
4203 @redundant[A @nt<requeue_statement>
4204 can be used to complete an @nt<accept_statement> or @nt<entry_body>,
4205 while redirecting the corresponding entry call to a new (or the same)
4206 entry queue.
4207 @Defn{requeue}
4208 Such a @i(requeue) can be performed with or without allowing
4209 an intermediate cancellation of the call, due to an abort or
4210 the expiration of a delay.
4211 @IndexSee{Term=[preference control],See=(requeue)}
4212 @IndexSee{Term=[broadcast signal],See=(requeue)}]
4213 @end{Intro}
4214
4215 @begin{Syntax}
4216 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2]}
4217 @Syn{lhs=<requeue_statement>,
4218 rhs="@key{requeue} @SynI{@Chg{Version=[3],New=[procedure_or_entry_],Old=[entry_]}}@Syn2{name} [@key{with} @key{abort}];"}
4219 @end{Syntax}
4220
4221 @begin{Resolution}
4222
4223 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
4224 @Chg{Version=[3],New=[@Defn{requeue target}],Old=[@Defn2{Term=[target entry], Sec=(of a @nt<requeue_statement>)}]}
4225 The @Chg{Version=[3],New=[@SynI{procedure_or_entry_}],Old=[@SynI(entry_)]}@nt{name}
4226 of a @nt{requeue_statement} shall resolve
4227 to denote @Chg{Version=[3],New=[a procedure or ],Old=[]}an entry (the
4228 @Chg{Version=[3],New=[@i{requeue }],Old=[]}@i{target}@Chg{Version=[3],New=[],
4229 Old=[@i{ entry}]})@Chg{Version=[3],New=[. The profile of
4230 the entry, or the profile or prefixed profile of the procedure, shall],Old=[that]}
4231 either @Chg{Version=[3],New=[have],Old=[has]} no parameters, or @Chg{Version=[3],
4232 New=[be],Old=[that has
4233 a profile that is]} type conformant (see @RefSecNum(Conformance Rules)) with
4234 the profile of the innermost enclosing @nt<entry_@!body> or
4235 @nt<accept_@!statement>.
4236 @Defn2{Term=[type conformance],Sec=(required)}
4237 @end{Resolution}
4238
4239 @begin{Legality}
4240
4241 A @nt{requeue_statement} shall be within a callable
4242 construct that is either an @nt{entry_body} or an
4243 @nt{accept_statement}, and this construct shall
4244 be the innermost enclosing body or callable construct.
4245
4246 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
4247 If the
4248 @Chg{Version=[3],New=[requeue ],Old=[]}target@Chg{Version=[3],New=[],Old=[ entry]}
4249 has parameters, then its @Chg{Version=[3],New=[(prefixed) ],Old=[]}profile
4250 shall be subtype conformant with
4251 the profile of the innermost enclosing callable construct.
4252 @Defn2{Term=[subtype conformance],Sec=(required)}
4253
4254 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0090-1]}
4255 @ChgAdded{Version=[4],Type=[Leading],Text=[Given a requeue_statement where the
4256 innermost enclosing callable construct is for an entry @i<E1>, for every
4257 @Redundant[specific or class-wide ]postcondition expression @i<P1> that
4258 applies to @i<E1>, there shall exist a postcondition expression @i<P2> that
4259 applies to the requeue target @i<E2> such that]}
4260 @begin{Itemize}
4261 @ChgRef{Version=[4],Kind=[Added]}
4262 @ChgAdded{Version=[4],Text=[@i<P1> is fully conformant with
4263 the expression produced by replacing each reference in @i<P2> to a formal
4264 parameter of @i<E2> with a reference to the corresponding formal paramter
4265 of @i<E1>; and]}
4266
4267 @ChgRef{Version=[4],Kind=[Added]}
4268 @ChgAdded{Version=[4],Text=[if @i<P1> is enabled, then @i<P2> is also enabled.]}
4269 @end{Itemize}
4270 @begin{Discussion}
4271 @ChgRef{Version=[4],Kind=[AddedNormal]}
4272 @ChgAdded{Version=[4],Text=[Roughly speaking, the postcondition of the requeue
4273 target is required to imply that of the enclosing callable construct.]}
4274 @end{Discussion}
4275
4276 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0090-1]}
4277 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0143-1]}
4278 @ChgAdded{Version=[4],Text=[The requeue target shall not have an applicable
4279 specific or class-wide postcondition @Chg{Version=[5],New=[that],Old=[which]}
4280 includes an Old@Chg{Version=[5],New=[ or Index @nt{attribute_reference}],
4281 Old=[attribute_reference]}.]}
4282
4283 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0090-1]}
4284 @ChgAdded{Version=[4],Text=[If the requeue target is declared immediately
4285 within the @nt{task_definition} of a named task type or the
4286 @nt{protected_definition} of a named protected type, and if the requeue
4287 statement occurs within the body of that type, and if the requeue is an external
4288 requeue, then the requeue target shall not have a specific or class-wide
4289 postcondition which includes a name denoting either the current instance of that
4290 type or any entity declared within the declaration of that type.]}
4291
4292 @begin{Discussion}
4293 @ChgRef{Version=[4],Kind=[AddedNormal]}
4294 @ChgAdded{Version=[4],Text=[The above pair of rules always apply; they
4295 don't depend on whether or not any of the postconditions are enabled.]}
4296 @end{Discussion}
4297
4298 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
4299 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0090-1]}@Comment{Just a number change}
4300 @ChgAdded{Version=[3],Text=[If the target is a procedure, the name shall
4301 denote a renaming of an entry, or shall denote a view or a prefixed view of a
4302 primitive subprogram of a synchronized interface, where the first parameter
4303 of the unprefixed view of the primitive subprogram shall be a
4304 controlling parameter, and the Synchronization aspect shall be specified
4305 with @nt{synchronization_kind} By_Entry for the primitive subprogram.]}
4306
4307 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2]}
4308 @PDefn2{Term=[accessibility rule],Sec=(requeue statement)}
4309 In a @nt<requeue_statement> of an @nt<accept_statement> of
4310 some task unit, either the target object shall be a part of a
4311 formal parameter of the @nt<accept_statement>,
4312 or the accessibility level of the target object
4313 shall not be equal to or statically deeper than any
4314 enclosing @nt<accept_statement> of the task unit.
4315 In a @nt<requeue_@!statement> of an @nt<entry_@!body>
4316 of some protected unit, either the target object shall be
4317 a part of a formal parameter of the @nt<entry_@!body>,
4318 or the accessibility level of the target object
4319 shall not be statically deeper than that
4320 of the @nt<entry_declaration>@Chg{Version=[3],New=[ for the @nt{entry_body}],Old=[]}.
4321
4322 @begin{Ramification}
4323 In the @nt{entry_body} case, the intent is that the target object can
4324 be global,
4325 or can be a component of the protected unit,
4326 but cannot be a local variable of the @nt{entry_body}.
4327 @end{Ramification}
4328 @begin(Reason)
4329 These restrictions ensure that the target object of the requeue outlives the
4330 completion and finalization of the enclosing callable construct.
4331 They also prevent requeuing from a nested
4332 @nt<accept_statement> on a parameter of an outer @nt<accept_statement>,
4333 which could create some strange "long-distance" connections between
4334 an entry caller and its server.
4335
4336 Note that in the strange case where a @nt<task_body> is nested inside
4337 an @nt<accept_statement>, it is permissible to requeue from an
4338 @nt<accept_statement> of the inner @nt<task_body> on parameters of
4339 the outer @nt<accept_statement>. This is not
4340 a problem because all calls on the inner task have to complete before
4341 returning from the outer @nt<accept_statement>, meaning no "dangling
4342 calls" will be created.
4343 @end(Reason)
4344 @begin(ImplNote)
4345 By disallowing certain requeues,
4346 we ensure that the normal @nt<terminate_alternative> rules remain
4347 sensible, and that explicit clearing of the entry queues of a protected
4348 object during finalization is rarely necessary. In particular, such
4349 clearing of the entry queues is necessary only (ignoring premature
4350 Unchecked_Deallocation) for protected objects declared in a
4351 @nt<task_body> (or created by an allocator for an access type declared
4352 in such a body) containing one or more @nt<requeue_statement>s.
4353 Protected objects declared in subprograms, or at the library level,
4354 will never need to have their entry queues explicitly cleared during
4355 finalization.
4356 @end(ImplNote)
4357 @end{Legality}
4358
4359 @begin{RunTime}
4360
4361 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2]}
4362 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0090-1]}
4363 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0335-1]}
4364 @ChgAdded{Version=[5],Type=[Leading],Text=[]}@Comment{Conditiona Leading}
4365 @PDefn2{Term=[execution], Sec=(requeue_statement)}
4366 The execution of a @nt{requeue_statement} @Chg{Version=[5],New=[begins with
4367 the following sequence of steps:],Old=[proceeds by first evaluating the
4368 @Chg{Version=[3],New=[@SynI{procedure_or_entry_}],Old=[@SynI(entry_)]}@nt<name>@Redundant[,
4369 including the @nt<prefix> identifying the target task
4370 or protected object and the @nt<expression> identifying the entry within an
4371 entry family, if any]. @Chg{Version=[4],New=[Precondition checks are then
4372 performed as for a call to the requeue target entry or subprogram. ],Old=[]}The
4373 @nt{entry_body} or @nt{accept_statement} enclosing the @nt{requeue_statement} is
4374 then completed@Redundant[, finalized, and
4375 left (see @RefSecNum(Completion and Finalization))].]}
4376
4377 @begin{Enumerate}
4378
4379 @ChgRef{Version=[5],Kind=[Added]}
4380 @ChgAdded{Version=[5],Text=[The @SynI{procedure_or_entry_}@nt{name}
4381 is evaluated. This includes evaluation of the @nt{prefix} (if any) identifying
4382 the target task or protected object and of the @nt{expression} (if any)
4383 identifying the entry within an entry family.]}
4384
4385 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0335-1]}
4386 @ChgAdded{Version=[5],Text=[If the target object is not a part of a formal
4387 parameter of the innermost enclosing callable construct, a check is made that
4388 the accessibility level of the target object is not equal to or deeper than
4389 the level of the innermost enclosing callable construct. If this check fails,
4390 Program_Error is raised.@Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}@IndexCheck{Accessibility_Check}]}
4391
4392 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0090-1]}
4393 @ChgAdded{Version=[5],Text=[Precondition checks are performed as for a call to
4394 the requeue target.]}
4395
4396 @ChgRef{Version=[5],Kind=[Added]}
4397 @ChgAdded{Version=[5],Text=[The @nt{entry_body} or @nt{accept_statement}
4398 enclosing the @nt{requeue_statement} is then completed@Redundant[, finalized,
4399 and left (see @RefSecNum(Completion and Finalization))].]}
4400
4401 @end{Enumerate}
4402
4403
4404
4405 @PDefn2{Term=[execution], Sec=(requeue task entry)}
4406 For the execution of a requeue on an entry of a target task,
4407 after leaving the enclosing callable construct, the named entry
4408 is checked to see if it is open and the requeued call is either
4409 selected immediately or queued, as for a normal entry call
4410 (see @RefSecNum(Entry Calls)).
4411
4412 @leading@PDefn2{Term=[execution], Sec=(requeue protected entry)}
4413 For the execution of a requeue on an entry of a target protected
4414 object, after leaving the enclosing callable construct:
4415 @begin(Itemize)
4416 if the requeue is an internal requeue
4417 (that is, the requeue is back on an entry of the same protected object @em
4418 see @RefSecNum(Intertask Communication)),
4419 the call is added to the queue of the named entry and
4420 the ongoing protected action continues (see @RefSecNum(Protected Subprograms and Protected Actions));
4421 @begin(Ramification)
4422 Note that for an internal requeue, the call
4423 is queued without checking whether the target entry is open.
4424 This is because the entry queues will be serviced before the
4425 current protected action completes anyway, and considering the
4426 requeued call immediately might allow it to "jump" ahead of
4427 existing callers on the same queue.
4428 @end(Ramification)
4429
4430 if the requeue is an external requeue (that is, the target protected
4431 object is not implicitly the same as the current object @em
4432 see @RefSecNum(Intertask Communication)),
4433 a protected action is started on the target object and proceeds
4434 as for a normal entry call (see @RefSecNum(Entry Calls)).
4435 @end(Itemize)
4436
4437 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0030-2]}
4438 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI05-0090-1]}
4439 If the @Chg{Version=[3],New=[requeue target],Old=[new entry]}
4440 named in the @nt<requeue_statement>
4441 has formal parameters, then during the execution of the
4442 @nt<accept_statement> or @nt<entry_body> corresponding to the new
4443 entry@Chg{Version=[4],New=[ and during the checking of
4444 any preconditions of the new entry],Old=[]},
4445 the formal parameters denote the same objects as
4446 did the corresponding formal parameters
4447 of the callable construct completed by the requeue.
4448 @Redundant[In any case, no parameters are specified in a
4449 @nt<requeue_statement>; any parameter passing is implicit.]
4450
4451 @leading@Defn{requeue-with-abort}
4452 If the @nt<requeue_statement> includes the reserved words @key(with abort)
4453 (it is a @i(requeue-with-abort)), then:
4454 @begin(Itemize)
4455 if the original entry call has been aborted
4456 (see @RefSecNum(Abort of a Task - Abort of a Sequence of Statements)), then
4457 the requeue acts as an abort completion point for the call,
4458 and the call is cancelled and no requeue is
4459 performed;
4460
4461 if the original entry call was timed (or conditional),
4462 then the original expiration time is the expiration
4463 time for the requeued call.
4464 @end(Itemize)
4465
4466 If the reserved words @key(with abort) do not appear, then the
4467 call remains protected against cancellation while queued as the result
4468 of the @nt<requeue_statement>.
4469 @begin(Ramification)
4470 This protection against cancellation lasts only until the
4471 call completes or a subsequent requeue-with-abort is performed
4472 on the call.
4473 @end(Ramification)
4474 @begin(Reason)
4475 We chose to protect a requeue, by default, against abort or cancellation.
4476 This seemed safer, since it is likely that extra steps need to be taken
4477 to allow for possible cancellation once the servicing of an entry
4478 call has begun. This also means that in the absence of @key(with abort)
4479 the usual Ada 83 behavior is preserved, namely that once an
4480 entry call is accepted, it cannot be cancelled until it completes.
4481 @end(Reason)
4482 @end{RunTime}
4483
4484 @begin{Notes}
4485
4486 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0300-1]}
4487 A requeue is permitted from a single entry to an entry of
4488 an entry family, or vice@Chg{Version=[5],New=[ ],Old=[-]}versa. The entry
4489 index, if any, plays no part in the subtype conformance check between the
4490 profiles of the two entries; an entry index
4491 is part of the @i(entry_)@nt<name> for an entry of a family.
4492 @PDefn{subtype conformance}
4493
4494 @end{Notes}
4495
4496 @begin{Examples}
4497 @leading@keepnext@i{Examples of requeue statements:}
4498 @begin{Example}
4499 @key[requeue] Request(Medium) @key[with abort];
4500 --@RI[ requeue on a member of an entry family of the current task, see @RefSecNum{Task Units and Task Objects}]
4501
4502 @key[requeue] Flags(I).Seize;
4503 --@RI[ requeue on an entry of an array component, see @RefSecNum{Protected Units and Protected Objects}]
4504 @end{Example}
4505 @end{Examples}
4506
4507 @begin{Extend83}
4508 @Defn{extensions to Ada 83}
4509 The @nt<requeue_statement> is new.
4510 @end{Extend83}
4511
4512 @begin{Extend2005}
4513 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0030-2],ARef=[AI05-0215-1]}
4514 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
4515 Added the ability
4516 to requeue on operations of synchronized interfaces that are
4517 declared to be an entry.]}
4518 @end{Extend2005}
4519
4520 @begin{Inconsistent2012}
4521 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0090-1]}
4522 @ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:>
4523 We now define that any preconditions of the requeue target are evaluated
4524 as part of a @nt<requeue_statement>. Original Ada 2012 did not specify this,
4525 so a program that requeues when the preconditions fail will raise an
4526 exception when none would happen in original Ada 2012. We don't expect this
4527 to be a problem, as in that case, the entry body would be called with some
4528 of its preconditions evaluating as False; the body is likely to assume that
4529 they are true and probably will have failed in some other way anyway.]}
4530
4531 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0335-1]}
4532 @ChgAdded{Version=[5],Text=[@b<Correction:> We now include an accessibility
4533 check on requeues. This means Program_Error could be raised for a requeue
4534 that worked in Ada 2012. This can only fail for an object for which the
4535 statically deeper relationship does not apply, for instance a stand-alone
4536 object of an anonymous access type. Most programs that are affected are
4537 erroneous anyway (as they will eventually use a nonexistent object), so we
4538 do not believe this will matter in practice.]}
4539 @end{Inconsistent2012}
4540
4541 @begin{Incompatible2012}
4542 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0090-1]}
4543 @ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:>
4544 If a requeue target has a different postcondition than the original
4545 entry, the requeue is now illegal. In such a case, the original postcondition
4546 would never have been evaluated, and assumptions that the caller relied upon
4547 might not be true. A requeue should be invisible to the caller with respect
4548 to any postconditions; thus we only allow it when the original entry has no
4549 postconditions or the requeue target has (at least) the same postconditions.]}
4550 @end{Incompatible2012}
4551
4552 @begin{DiffWord2012}
4553 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0143-1]}
4554 @ChgAdded{Version=[5],Text=[Added a @LegalityName for the new Index
4555 attribute (see @RefSecNum{Preconditions and Postconditions}).]}
4556 @end{DiffWord2012}
4557
4558
4559 @LabeledClause{Delay Statements, Duration, and Time}
4560
4561 @begin{Intro}
4562 @redundant[@PDefn{expiration time}
4563 A @nt<delay_statement> is used to block further execution until
4564 a specified @i(expiration time) is reached.
4565 The expiration time
4566 can be specified either as a particular point in time (in a
4567 @nt<delay_@!until_@!statement>), or in seconds from the current time
4568 (in a @nt<delay_@!relative_@!statement>).
4569 The language-defined
4570 package Calendar provides definitions for a type Time and associated
4571 operations, including a function Clock that returns the current time.
4572 @IndexSee{Term=[timing],See=(delay_statement)}]
4573 @end{Intro}
4574
4575 @begin{Syntax}
4576 @Syn{lhs=<delay_statement>,
4577 rhs="@Syn2{delay_until_statement} | @Syn2{delay_relative_statement}"}
4578
4579
4580 @Syn{lhs=<delay_until_statement>,
4581 rhs="@key{delay until} @SynI(delay_)@Syn2{expression};"}
4582
4583 @Syn{lhs=<delay_relative_statement>,
4584 rhs="@key{delay} @SynI(delay_)@Syn2{expression};"}
4585 @end{Syntax}
4586
4587 @begin{Resolution}
4588
4589 @PDefn2{Term=[expected type],
4590 Sec=(delay_relative_statement expression)}
4591 The expected type for the @i(delay_)@nt{expression} in a
4592 @nt{delay_relative_statement} is the predefined type Duration.
4593 @PDefn2{Term=[expected type],
4594 Sec=(delay_until_statement expression)}
4595 The @i(delay_)@nt<expression> in a @nt<delay_until_statement>
4596 is expected to be of any nonlimited type.
4597
4598 @end{Resolution}
4599
4600 @begin{Legality}
4601
4602 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4603 @Defn{time type}
4604 @Defn{time base}
4605 @Defn{clock}
4606 There can be multiple time bases, each with a corresponding
4607 clock, and a corresponding @i{time type}.
4608 The type of the @i(delay_)@nt<expression>
4609 in a @nt{delay_until_statement} shall be a time type @em either the
4610 type Time defined in the language-defined package Calendar (see
4611 below),@Chg{Version=[3],New=[ the type Time in the package Real_Time
4612 (see @RefSecNum(Monotonic Time)),],Old=[]}
4613 or some other implementation-defined time type@Chg{Version=[3],New=[],Old=[
4614 (see @RefSecNum(Monotonic Time))]}.
4615 @ImplDef{Any implementation-defined time types.}
4616 @end{Legality}
4617
4618 @begin{StaticSem}
4619 @Redundant[There is a predefined fixed point type
4620 named Duration, declared in the visible part of package Standard;]
4621 a value of type Duration is used to represent the length
4622 of an interval of time, expressed in seconds.
4623 @Redundant[The type Duration is not specific to a particular time base,
4624 but can be used with any time base.]
4625
4626 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4627 A value of the type Time in package Calendar, or of some other
4628 @Chg{Version=[3],New=[],Old=[implementation-defined ]}time type,
4629 represents a time as reported by a corresponding clock.
4630
4631 @leading@keepnext@;The following language-defined library package exists:
4632 @begin{Example}
4633 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
4634 @ChildUnit{Parent=[Ada],Child=[Calendar]}
4635 @key(package) Ada.Calendar @Chg{Version=[5],New=[
4636 @key(with) Nonblocking ],Old=[]}@key(is)
4637 @key(type) @AdaTypeDefn{Time} @key(is) @key(private);
4638
4639 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00351-01]}
4640 @key(subtype) @AdaSubtypeDefn{Name=[Year_Number],Of=[Integer]} @key(is) Integer @key(range) 1901 .. @Chg{Version=[2],New=[2399],Old=[2099]};
4641 @key(subtype) @AdaSubtypeDefn{Name=[Month_Number],Of=[Integer]} @key(is) Integer @key(range) 1 .. 12;
4642 @key(subtype) @AdaSubtypeDefn{Name=[Day_Number],Of=[Integer]} @key(is) Integer @key(range) 1 .. 31;
4643 @key(subtype) @AdaSubtypeDefn{Name=[Day_Duration],Of=[Duration]} @key(is) Duration @key(range) 0.0 .. 86_400.0;
4644
4645 @begin{Reason}
4646 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
4647 @ChgAdded{Version=[2],Text=[A range of 500 years was chosen, as that only
4648 requires one extra bit for the year as compared to Ada 95. This was done
4649 to minimize disruptions with existing implementations. (One implementor
4650 reports that their time values represent nanoseconds, and this year range
4651 requires 63.77 bits to represent.)]}
4652 @end{Reason}
4653
4654 @key(function) @AdaSubDefn{Clock} @key(return) Time;
4655
4656 @key(function) @AdaSubDefn{Year} (Date : Time) @key(return) Year_Number;
4657 @key(function) @AdaSubDefn{Month} (Date : Time) @key(return) Month_Number;
4658 @key(function) @AdaSubDefn{Day} (Date : Time) @key(return) Day_Number;
4659 @key(function) @AdaSubDefn{Seconds}(Date : Time) @key(return) Day_Duration;
4660
4661 @key(procedure) @AdaSubDefn{Split} (Date : @key(in) Time;
4662 Year : @key(out) Year_Number;
4663 Month : @key(out) Month_Number;
4664 Day : @key(out) Day_Number;
4665 Seconds : @key(out) Day_Duration);
4666
4667 @key(function) @AdaSubDefn{Time_Of}(Year : Year_Number;
4668 Month : Month_Number;
4669 Day : Day_Number;
4670 Seconds : Day_Duration := 0.0)
4671 @key(return) Time;
4672
4673 @key(function) "+" (Left : Time; Right : Duration) @key(return) Time;
4674 @key(function) "+" (Left : Duration; Right : Time) @key(return) Time;
4675 @key(function) "-" (Left : Time; Right : Duration) @key(return) Time;
4676 @key(function) "-" (Left : Time; Right : Time) @key(return) Duration;
4677
4678 @key(function) "<" (Left, Right : Time) @key(return) Boolean;
4679 @key(function) "<="(Left, Right : Time) @key(return) Boolean;
4680 @key(function) ">" (Left, Right : Time) @key(return) Boolean;
4681 @key(function) ">="(Left, Right : Time) @key(return) Boolean;
4682
4683 @AdaExcDefn{Time_Error} : @key(exception;)
4684
4685 @key(private)
4686 ... -- @RI{not specified by the language}
4687 @key(end) Ada.Calendar;
4688
4689 @end{Example}
4690
4691 @end{StaticSem}
4692
4693 @begin{RunTime}
4694 @PDefn2{Term=[execution], Sec=(delay_statement)}
4695 For the execution of a @nt<delay_statement>, the @i(delay_)@nt<expression>
4696 is first evaluated.
4697 @Defn2{Term=[expiration time], Sec=(for a @nt<delay_until_statement>)}
4698 For a @nt<delay_until_statement>, the expiration time for the
4699 delay is the value of the @i(delay_)@nt<expression>, in the time
4700 base associated with the type of the @nt<expression>.
4701 @Defn2{Term=[expiration time], Sec=(for a @nt<delay_relative_statement>)}
4702 For a @nt<delay_relative_statement>, the expiration time is
4703 defined as the current time, in the time base associated
4704 with relative delays, plus
4705 the value of the @i(delay_)@nt<expression>
4706 converted to the type Duration, and then rounded up
4707 to the next clock tick.
4708 @PDefn2{Term=[implicit subtype conversion],Sec=(delay expression)}
4709 The time base associated with relative delays
4710 is as defined in @RefSec{Delay Accuracy} or is
4711 implementation defined.
4712 @ImplDef{The time base associated with relative delays.}
4713 @begin{Ramification}
4714 Rounding up to the next clock tick means that the reading of the
4715 delay-relative clock when the delay expires should be no less than
4716 the current reading of the delay-relative
4717 clock plus the specified duration.
4718 @end{Ramification}
4719
4720 @PDefn2{Term=[blocked], Sec=(on a @nt<delay_statement>)}
4721 The task executing a @nt<delay_statement> is blocked
4722 until the expiration time is reached, at which point it
4723 becomes ready again. If the expiration time
4724 has already passed, the task is not blocked.
4725 @begin(Discussion)
4726 For a @nt<delay_relative_statement>, this case corresponds to
4727 when the value of the @i(delay_)@nt<expression> is zero
4728 or negative.
4729
4730 Even though the task is not blocked,
4731 it might be put back on the end of its ready queue.
4732 See @RefSec(Priority Scheduling).
4733 @end(Discussion)
4734
4735 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4736 @Defn2{Term=[cancellation], Sec=(of a @nt<delay_statement>)}
4737 If an attempt is made to @i(cancel) the @nt<delay_statement>
4738 @Redundant[(as part of an @nt<asynchronous_@!select> or abort @em
4739 see @RefSecNum{Asynchronous Transfer of Control} and
4740 @RefSecNum{Abort of a Task - Abort of a Sequence of Statements})],
4741 the @Chg{Version=[3],New=[statement],Old=[@ntf<_statement>]}
4742 is cancelled if the expiration time has not yet passed,
4743 thereby completing the @nt<delay_statement>.
4744 @begin(Reason)
4745 This is worded this way so that in an @nt<asynchronous_select>
4746 where the @nt<triggering_statement> is a @nt<delay_statement>,
4747 an attempt to cancel the delay when the @nt<abortable_part> completes
4748 is ignored if the expiration time has already passed, in which case the
4749 optional statements of the @nt<triggering_alternative> are executed.
4750 @end(Reason)
4751
4752 The time base associated with the type Time of package Calendar
4753 is implementation defined. The function Clock of package Calendar
4754 returns a value representing the current time for this time base.
4755 @Redundant[The implementation-defined value of the
4756 named number System.Tick (see @RefSecNum(The Package System))
4757 is an approximation of the length of the real-time
4758 interval during which the value of Calendar.Clock remains constant.]
4759 @ImplDef{The time base of the type Calendar.Time.}
4760
4761 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00351-01]}
4762 The functions Year,
4763 Month, Day, and Seconds return the corresponding values for
4764 a given value of the type Time,
4765 as appropriate to an implementation-defined
4766 @Chg{Version=[2],New=[time zone],Old=[timezone]}; the procedure Split
4767 returns all four
4768 corresponding values. Conversely, the function Time_Of combines a
4769 year number, a month number, a day number, and a duration, into
4770 a value of type Time. The operators "+" and "@en@;" for addition
4771 and subtraction of times and durations, and the relational operators
4772 for times, have the conventional meaning.
4773 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
4774 Text=[The @Chg{Version=[2],New=[time zone],Old=[timezone]} used for
4775 package Calendar operations.]}
4776
4777 @begin{Ramification}
4778 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0119-1]}
4779 @ChgAdded{Version=[3],Text=[The behavior of these values and subprograms if
4780 the time zone changes is also implementation-defined. In particular, the
4781 changes associated with summer time adjustments (like Daylight Savings Time in
4782 the United States) should be treated as a change in the implementation-defined
4783 time zone. The language does not specify whether the time zone information is
4784 stored in values of type Time; therefore the results of binary operators are
4785 unspecified when the operands are the two values with different
4786 effective time zones. In particular, the results of "-" may differ from the
4787 "real" result by the difference in the time zone adjustment. Similarly, the
4788 result of UTC_Time_Offset (see 9.6.1) may or may not reflect a time zone
4789 adjustment.]}
4790 @end{Ramification}
4791
4792 If Time_Of is called with a seconds value of 86_400.0, the value
4793 returned is equal to the value of Time_Of for the next day
4794 with a seconds value of 0.0.
4795 The value returned by the function
4796 Seconds or through the Seconds parameter of the procedure
4797 Split is always less than 86_400.0.
4798
4799 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0030],ARef=[AI95-00113-01]}
4800 The exception Time_Error is raised by the function Time_Of if the
4801 actual parameters do not form a proper date. This exception
4802 is also raised by the operators "+" and "@en@;" if the
4803 result is not representable in the type Time or Duration, as appropriate.
4804 This exception is also raised by the
4805 function@Chg{New=[s],Old=[]} Year@Chg{New=[, Month, Day, and Seconds and],
4806 Old=[or]} the procedure Split if the year number of the given date is
4807 outside of the range of the subtype Year_Number.
4808 @begin(Honest)
4809 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0106],ARef=[AI95-00160-01]}
4810 By "proper date" above we mean that the given year has
4811 a month with the given day. For example, February 29th is
4812 a proper date only for a leap year. @Chg{New=[We do not mean to include
4813 the Seconds in this notion; in particular, we do not mean to require
4814 implementations to check for the @lquotes@;missing hour@rquotes that occurs
4815 when Daylight Savings Time starts in the spring.],Old=[]}
4816 @end(Honest)
4817 @begin(Reason)
4818 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0030],ARef=[AI95-00113-01]}
4819 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00351-01]}
4820 We allow Year and Split to raise Time_Error because the arithmetic operators
4821 are allowed (but not required) to produce times that are outside the range
4822 of years from 1901 to @Chg{Version=[2],New=[2399],Old=[2099]}. This is
4823 similar to the way integer operators may
4824 return values outside the base range of their type so long as the value is
4825 mathematically correct.
4826 @Chg{New=[We allow the functions Month, Day and Seconds to raise Time_Error
4827 so that they can be implemented in terms of Split.],Old=[]}
4828 @end(Reason)
4829 @end{RunTime}
4830
4831 @begin{ImplReq}
4832 The implementation of the type Duration shall allow representation of
4833 time intervals (both positive and negative) up to at least 86400 seconds (one
4834 day); Duration'Small shall not be greater than twenty milliseconds.
4835 The implementation of the type Time shall allow representation of
4836 all dates with year numbers in the range of Year_Number@Redundant[; it
4837 may allow representation of other dates as well (both earlier and later).]
4838 @end{ImplReq}
4839
4840 @begin{ImplPerm}
4841
4842 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0092-1]}
4843 An implementation may define additional time
4844 types@Chg{Version=[3],New=[],Old=[ (see @RefSecNum{Monotonic Time})]}.
4845
4846 An implementation may raise Time_Error if the
4847 value of a @i{delay_}@nt<expression> in a @nt<delay_until_statement>
4848 of a @nt<select_statement> represents a time more than 90 days past the
4849 current time. The actual limit, if any, is implementation-defined.
4850 @ImplDef{Any limit on @nt<delay_until_statement>s of @nt<select_statement>s.}
4851 @begin{ImplNote}
4852 This allows an implementation to implement @nt<select_statement>
4853 timeouts using
4854 a representation that does not support the full range of a time type.
4855 In particular 90 days of seconds can be represented in 23 bits,
4856 allowing a signed 24-bit representation for the seconds part of
4857 a timeout.
4858 There is no similar restriction allowed for stand-alone
4859 @nt<delay_until_statement>s, as these can be implemented
4860 internally using a loop if necessary to accommodate a long delay.
4861 @end{ImplNote}
4862
4863 @end{ImplPerm}
4864
4865 @begin{ImplAdvice}
4866
4867 Whenever possible in an implementation, the value of
4868 Duration'Small should be no greater than 100 microseconds.
4869 @begin(ImplNote)
4870 This can be satisfied using a 32-bit 2's complement representation
4871 with a @i(small) of 2.0**(@en@;14) @em that is, 61 microseconds @em and a
4872 range of @PorM 2.0**17 @em that is, 131_072.0.
4873 @end(ImplNote)
4874 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4875 Text=[The value of Duration'Small should be no greater than 100 microseconds.]}]}
4876
4877 The time base for @nt{delay_relative_statement}s should be monotonic;
4878 it need not be the same time base as used for Calendar.Clock.
4879 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
4880 Text=[The time base for @nt{delay_relative_statement}s should be monotonic.]}]}
4881
4882 @end{ImplAdvice}
4883
4884 @begin{Notes}
4885
4886 A @nt{delay_relative_statement} with a negative value of the
4887 @i(delay_)@nt<expression> is equivalent to one with a zero value.
4888
4889 A @nt{delay_statement} may be executed by the environment task;
4890 consequently @nt{delay_statement}s may be executed as part of
4891 the elaboration of a @nt{library_item} or the execution of the main subprogram.
4892 Such statements delay the environment task (see @RefSecNum(Program Execution)).
4893
4894 @PDefn2{Term=[potentially blocking operation],Sec=(delay_statement)}
4895 @PDefn2{Term=[blocking, potentially],Sec=(delay_statement)}
4896 A @nt{delay_statement} is an abort completion point and
4897 a potentially blocking operation,
4898 even if the task is not actually blocked.
4899
4900 There is no necessary relationship between System.Tick (the
4901 resolution of the clock of package Calendar)
4902 and Duration'Small (the @i(small) of type Duration).
4903 @begin{Ramification}
4904 The inaccuracy of the @nt{delay_statement} has no relation to System.Tick.
4905 In particular, it is possible that the clock used for the
4906 @nt{delay_statement} is less accurate than Calendar.Clock.
4907
4908 We considered making Tick a run-time-determined quantity,
4909 to allow for easier configurability.
4910 However, this would not be upward compatible,
4911 and the desired configurability can be achieved using
4912 functionality defined in @RefSec{Real-Time Systems}.
4913 @end{Ramification}
4914
4915 Additional requirements associated with @nt<delay_statement>s
4916 are given in @RefSec(Delay Accuracy).
4917
4918 @end{Notes}
4919
4920 @begin{Examples}
4921 @leading@keepnext@i{Example of a relative delay statement:}
4922 @begin{example}
4923 @key(delay) 3.0; --@RI[ delay 3.0 seconds]
4924 @end{example}
4925
4926 @begin{WideAbove}
4927 @leading@keepnext@Defn2{Term=[periodic task],Sec=(example)}
4928 @IndexSee{Term=[periodic task],See=(delay_until_statement)}
4929 @i{Example of a periodic task:}
4930 @end{WideAbove}
4931 @begin{example}
4932 @key(declare)
4933 @key(use) Ada.Calendar;
4934 Next_Time : Time := Clock + Period;
4935 --@RI[ Period is a global constant of type Duration]
4936 @key(begin)
4937 @key(loop) --@RI[ repeated every Period seconds]
4938 @key(delay) @key(until) Next_Time;
4939 ... --@RI[ perform some actions]
4940 Next_Time := Next_Time + Period;
4941 @key(end) @key(loop;)
4942 @key(end;)
4943 @end{example}
4944 @end{Examples}
4945
4946 @begin{Inconsistent83}
4947 @Defn{inconsistencies with Ada 83}
4948 For programs that raise Time_Error on "+" or "@en@;" in Ada 83,the exception
4949 might be deferred until a call on Split or Year_Number, or might
4950 not be raised at all (if the offending time is never Split after being
4951 calculated). This should not affect typical programs,
4952 since they deal only with times corresponding to the relatively
4953 recent past or near future.
4954 @end{Inconsistent83}
4955
4956 @begin{Extend83}
4957 @Defn{extensions to Ada 83}
4958 The syntax rule for @nt{delay_statement} is modified to allow
4959 @nt{delay_until_statement}s.
4960
4961 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00351-01]}
4962 The type Time may represent dates with year numbers outside of Year_Number.
4963 Therefore, the operations "+" and
4964 "@en@;" need only raise Time_Error if the result is not representable
4965 in Time (or Duration); also, Split or Year will now raise Time_Error
4966 if the year number is outside of Year_Number.
4967 This change is intended to simplify the implementation
4968 of "+" and "@en@;" (allowing them to depend on overflow for
4969 detecting when to raise Time_Error) and to allow local
4970 @Chg{Version=[2],New=[time zone],Old=[timezone]} information to be
4971 considered at the time of Split rather than Clock (depending on
4972 the implementation approach). For example, in a POSIX environment,
4973 it is natural for the type Time to be based on GMT, and
4974 the results of procedure Split (and the functions
4975 Year, Month, Day, and Seconds) to depend on local time zone information.
4976 In other environments, it is more natural for the type Time to
4977 be based on the local time zone, with the results of
4978 Year, Month, Day, and Seconds being pure functions of their input.
4979
4980 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00351-01]}
4981 @ChgDeleted{Version=[2],Text=[We anticipate that implementations will provide
4982 child packages of Calendar to provide more explicit control over time zones
4983 and other environment-dependent time-related issues.
4984 These would be appropriate for standardization in a given
4985 environment (such as POSIX).]}
4986 @end{Extend83}
4987
4988 @begin{Inconsistent95}
4989 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
4990 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}The upper bound
4991 of Year_Number has been changed to avoid a year 2100 problem. A program
4992 which expects years past 2099 to raise Constraint_Error will fail in Ada 2005.
4993 We don't expect there to be many programs which are depending on an exception
4994 to be raised. A program that uses Year_Number'Last as a magic number may also
4995 fail if values of Time are stored outside of the program.
4996 Note that the lower bound of Year_Number wasn't changed, because
4997 it is not unusual to use that value in a constant to represent an unknown
4998 time.]}
4999 @end{Inconsistent95}
5000
5001 @begin{DiffWord95}
5002 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
5003 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that Month, Day, and
5004 Seconds can raise Time_Error.]}
5005 @end{DiffWord95}
5006
5007
5008 @LabeledAddedSubclause{Version=[2],Name=[Formatting, Time Zones, and other operations for Time]}
5009
5010 @begin{StaticSem}
5011
5012 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5013 @ChgAdded{Version=[2],Text=[The following language-defined library packages exist:]}
5014
5015 @begin{Example}
5016 @ChgRef{Version=[2],Kind=[AddedNormal]}
5017 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
5018 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Calendar],Child=[Time_Zones]}@key(package) Ada.Calendar.Time_Zones @Chg{Version=[5],New=[
5019 @key(with) Nonblocking ],Old=[]}@key(is)]}
5020
5021 @ChgRef{Version=[2],Kind=[AddedNormal]}
5022 @ChgAdded{Version=[2],Text=[ -- @RI[Time zone manipulation:]]}
5023
5024 @ChgRef{Version=[2],Kind=[AddedNormal]}
5025 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Time_Offset} @key<is range> -28*60 .. 28*60;]}
5026
5027 @begin{Reason}
5028 @ChgRef{Version=[2],Kind=[AddedNormal]}
5029 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]}
5030 @ChgAdded{Version=[2],Text=[We want to be able to specify the difference
5031 between any two arbitrary time zones. You might think that 1440 (24 hours)
5032 would be enough, but there are places (like Tonga, which is UTC+13hr) which
5033 are more than 12 hours @Chg{Version=[4],New=[different ],Old=[]}than UTC.
5034 Combined with summer time (known as daylight saving time in some parts of the
5035 world) @en which switches opposite in the northern and
5036 @Chg{Version=[4],New=[southern],Old=[souther]} hemispheres @en and even greater
5037 differences are possible. We know of cases of a 26 hours difference, so we err
5038 on the safe side by selecting 28 hours as the limit.]}
5039 @end{Reason}
5040
5041 @ChgRef{Version=[2],Kind=[AddedNormal]}
5042 @ChgAdded{Version=[2],Text=[ @AdaExcDefn{Unknown_Zone_Error} : @key<exception>;]}
5043
5044 @ChgRef{Version=[2],Kind=[AddedNormal]}
5045 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5046 @ChgAdded{Version=[2],Text=[ @key<function> @Chg{Version=[5],New=[@AdaSubDefn{Local_Time_Offset}],Old=[@AdaSubDefn{UTC_Time_Offset}]} (Date : Time := Clock) @key<return> Time_Offset;]}
5047
5048 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0336-1]}
5049 @ChgAdded{Version=[5],Text=[ @key<function> @AdaSubDefn{UTC_Time_Offset} (Date : Time := Clock) @key<return> Time_Offset
5050 @key<renames> Local_Time_Offset;]}
5051
5052 @ChgRef{Version=[2],Kind=[AddedNormal]}
5053 @ChgAdded{Version=[2],Text=[@key<end> Ada.Calendar.Time_Zones;]}
5054
5055 @ChgRef{Version=[2],Kind=[AddedNormal]}
5056 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
5057 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Calendar],Child=[Arithmetic]}
5058 @key(package) Ada.Calendar.Arithmetic @Chg{Version=[5],New=[
5059 @key(with) Nonblocking ],Old=[]}@key(is)]}
5060
5061 @ChgRef{Version=[2],Kind=[AddedNormal]}
5062 @ChgAdded{Version=[2],Text=[ -- @RI[Arithmetic on days:]]}
5063
5064 @ChgRef{Version=[2],Kind=[AddedNormal]}
5065 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Day_Count} @key<is range>
5066 -366*(1+Year_Number'Last - Year_Number'First)
5067 ..
5068 366*(1+Year_Number'Last - Year_Number'First);]}
5069
5070 @ChgRef{Version=[2],Kind=[AddedNormal]}
5071 @ChgAdded{Version=[2],Text=[ @key<subtype> @AdaSubtypeDefn{Name=[Leap_Seconds_Count],Of=[Integer]} @key<is> Integer @key<range> -2047 .. 2047;]}
5072
5073 @begin{Reason}
5074 @ChgRef{Version=[2],Kind=[AddedNormal]}
5075 @ChgAdded{Version=[2],Text=[The maximum number of leap seconds is likely
5076 to be much less than this, but we don't want to reach the limit too soon
5077 if the earth's behavior suddenly changes. We believe that the maximum number
5078 is 1612, based on the current rules, but that number is too weird to use here.]}
5079 @end{Reason}
5080
5081 @ChgRef{Version=[2],Kind=[AddedNormal]}
5082 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Difference} (Left, Right : @key<in> Time;
5083 Days : @key<out> Day_Count;
5084 Seconds : @key<out> Duration;
5085 Leap_Seconds : @key<out> Leap_Seconds_Count);]}
5086
5087 @ChgRef{Version=[2],Kind=[AddedNormal]}
5088 @ChgAdded{Version=[2],Text=[ @key<function> "+" (Left : Time; Right : Day_Count) @key<return> Time;
5089 @key<function> "+" (Left : Day_Count; Right : Time) @key<return> Time;
5090 @key<function> "-" (Left : Time; Right : Day_Count) @key<return> Time;
5091 @key<function> "-" (Left, Right : Time) @key<return> Day_Count;]}
5092
5093 @ChgRef{Version=[2],Kind=[AddedNormal]}
5094 @ChgAdded{Version=[2],Text=[@key<end> Ada.Calendar.Arithmetic;]}
5095
5096 @ChgRef{Version=[2],Kind=[AddedNormal]}
5097 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
5098 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada.Calendar],Child=[Formatting]}
5099 @key<with> Ada.Calendar.Time_Zones;
5100 @key(package) Ada.Calendar.Formatting @Chg{Version=[5],New=[
5101 @key(with) Nonblocking ],Old=[]}@key(is)]}
5102
5103 @ChgRef{Version=[2],Kind=[AddedNormal]}
5104 @ChgAdded{Version=[2],Text=[ -- @RI[Day of the week:]]}
5105
5106 @ChgRef{Version=[2],Kind=[AddedNormal]}
5107 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Day_Name} @key<is> (@AdaObjDefn{Monday}, @AdaObjDefn{Tuesday}, @AdaObjDefn{Wednesday}, @AdaObjDefn{Thursday},
5108 @AdaObjDefn{Friday}, @AdaObjDefn{Saturday}, @AdaObjDefn{Sunday});]}
5109
5110 @ChgRef{Version=[2],Kind=[AddedNormal]}
5111 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Day_of_Week} (Date : Time) @key<return> Day_Name;]}
5112
5113 @ChgRef{Version=[2],Kind=[AddedNormal]}
5114 @ChgAdded{Version=[2],Text=[ -- @RI[Hours:Minutes:Seconds access:]]}
5115
5116 @ChgRef{Version=[2],Kind=[AddedNormal]}
5117 @ChgAdded{Version=[2],Text=[ @key<subtype> @AdaSubtypeDefn{Name=[Hour_Number],Of=[Natural]} @key<is> Natural @key<range> 0 .. 23;
5118 @key<subtype> @AdaSubtypeDefn{Name=[Minute_Number],Of=[Natural]} @key<is> Natural @key<range> 0 .. 59;
5119 @key<subtype> @AdaSubtypeDefn{Name=[Second_Number],Of=[Natural]} @key<is> Natural @key<range> 0 .. 59;
5120 @key<subtype> @AdaSubtypeDefn{Name=[Second_Duration],Of=[Day_Duration]} @key<is> Day_Duration @key<range> 0.0 .. 1.0;]}
5121
5122 @ChgRef{Version=[2],Kind=[AddedNormal]}
5123 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Year} (Date : Time;
5124 Time_Zone : Time_Zones.Time_Offset := 0)
5125 @key<return> Year_Number;]}
5126
5127 @ChgRef{Version=[2],Kind=[AddedNormal]}
5128 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Month} (Date : Time;
5129 Time_Zone : Time_Zones.Time_Offset := 0)
5130 @key<return> Month_Number;]}
5131
5132 @ChgRef{Version=[2],Kind=[AddedNormal]}
5133 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Day} (Date : Time;
5134 Time_Zone : Time_Zones.Time_Offset := 0)
5135 @key<return> Day_Number;]}
5136
5137 @ChgRef{Version=[2],Kind=[AddedNormal]}
5138 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Hour} (Date : Time;
5139 Time_Zone : Time_Zones.Time_Offset := 0)
5140 @key<return> Hour_Number;]}
5141
5142 @ChgRef{Version=[2],Kind=[AddedNormal]}
5143 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Minute} (Date : Time;
5144 Time_Zone : Time_Zones.Time_Offset := 0)
5145 @key<return> Minute_Number;]}
5146
5147 @ChgRef{Version=[2],Kind=[AddedNormal]}
5148 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Second} (Date : Time)
5149 @key<return> Second_Number;]}
5150
5151 @ChgRef{Version=[2],Kind=[AddedNormal]}
5152 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Sub_Second} (Date : Time)
5153 @key<return> Second_Duration;]}
5154
5155 @ChgRef{Version=[2],Kind=[AddedNormal]}
5156 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Seconds_Of} (Hour : Hour_Number;
5157 Minute : Minute_Number;
5158 Second : Second_Number := 0;
5159 Sub_Second : Second_Duration := 0.0)
5160 @key<return> Day_Duration;]}
5161
5162 @ChgRef{Version=[2],Kind=[AddedNormal]}
5163 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Split} (Seconds : @key<in> Day_Duration;
5164 Hour : @key<out> Hour_Number;
5165 Minute : @key<out> Minute_Number;
5166 Second : @key<out> Second_Number;
5167 Sub_Second : @key<out> Second_Duration);]}
5168
5169 @ChgRef{Version=[2],Kind=[AddedNormal]}
5170 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Time_Of} (Year : Year_Number;
5171 Month : Month_Number;
5172 Day : Day_Number;
5173 Hour : Hour_Number;
5174 Minute : Minute_Number;
5175 Second : Second_Number;
5176 Sub_Second : Second_Duration := 0.0;
5177 Leap_Second: Boolean := False;
5178 Time_Zone : Time_Zones.Time_Offset := 0)
5179 @key<return> Time;]}
5180
5181 @ChgRef{Version=[2],Kind=[AddedNormal]}
5182 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Time_Of} (Year : Year_Number;
5183 Month : Month_Number;
5184 Day : Day_Number;
5185 Seconds : Day_Duration := 0.0;
5186 Leap_Second: Boolean := False;
5187 Time_Zone : Time_Zones.Time_Offset := 0)
5188 @key<return> Time;]}
5189
5190 @ChgRef{Version=[2],Kind=[AddedNormal]}
5191 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Split} (Date : @key<in> Time;
5192 Year : @key<out> Year_Number;
5193 Month : @key<out> Month_Number;
5194 Day : @key<out> Day_Number;
5195 Hour : @key<out> Hour_Number;
5196 Minute : @key<out> Minute_Number;
5197 Second : @key<out> Second_Number;
5198 Sub_Second : @key<out> Second_Duration;
5199 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5200
5201 @ChgRef{Version=[2],Kind=[AddedNormal]}
5202 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Split} (Date : @key<in> Time;
5203 Year : @key<out> Year_Number;
5204 Month : @key<out> Month_Number;
5205 Day : @key<out> Day_Number;
5206 Hour : @key<out> Hour_Number;
5207 Minute : @key<out> Minute_Number;
5208 Second : @key<out> Second_Number;
5209 Sub_Second : @key<out> Second_Duration;
5210 Leap_Second: @key<out> Boolean;
5211 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5212
5213 @ChgRef{Version=[2],Kind=[AddedNormal]}
5214 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Split} (Date : @key<in> Time;
5215 Year : @key<out> Year_Number;
5216 Month : @key<out> Month_Number;
5217 Day : @key<out> Day_Number;
5218 Seconds : @key<out> Day_Duration;
5219 Leap_Second: @key<out> Boolean;
5220 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5221
5222 @ChgRef{Version=[2],Kind=[AddedNormal]}
5223 @ChgAdded{Version=[2],Text=[ -- @RI[Simple image and value:]
5224 @key<function> @AdaSubDefn{Image} (Date : Time;
5225 Include_Time_Fraction : Boolean := False;
5226 Time_Zone : Time_Zones.Time_Offset := 0) @key<return> String;]}
5227
5228 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0336-1],ARef=[AI12-0347-1]}
5229 @ChgAdded{Version=[5],Text=[ @key<function> @AdaSubDefn{Local_Image} (Date : Time;
5230 Include_Time_Fraction : Boolean := False) @key<return> String @key<is>
5231 (Image (Date, Include_Time_Fraction, Time_Zones.Local_Time_Offset (Date)));]}
5232
5233 @ChgRef{Version=[2],Kind=[AddedNormal]}
5234 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Value} (Date : String;
5235 Time_Zone : Time_Zones.Time_Offset := 0) @key<return> Time;]}
5236
5237 @ChgRef{Version=[2],Kind=[AddedNormal]}
5238 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Image} (Elapsed_Time : Duration;
5239 Include_Time_Fraction : Boolean := False) @key<return> String;]}
5240
5241 @ChgRef{Version=[2],Kind=[AddedNormal]}
5242 @ChgAdded{Version=[2],Text=[ @key<function> @AdaSubDefn{Value} (Elapsed_Time : String) @key<return> Duration;]}
5243
5244 @ChgRef{Version=[2],Kind=[AddedNormal]}
5245 @ChgAdded{Version=[2],Text=[@key<end> Ada.Calendar.Formatting;]}
5246
5247 @end{Example}
5248
5249 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5250 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5251 @ChgAdded{Version=[2],Text=[Type Time_Offset represents
5252 @Chg{Version=[5],New=[for a given locality at a given moment ],Old=[]} the
5253 number of minutes
5254 @Chg{Version=[5],New=[the local time is,
5255 at that moment, ahead (+) or behind (-) Coordinated Universal Time
5256 (abbreviated UTC).@Redundant[ The Time_Offset for UTC is
5257 zero]],Old=[difference between the implementation-defined time zone used
5258 by Calendar and another time zone]}.]}
5259
5260 @begin{DescribeCode}
5261
5262 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5263 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5264 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> @Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]} (Date : Time := Clock) @key<return> Time_Offset;]}
5265 @end{Example}
5266 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5267 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0119-1],ARef=[AI05-0269-1]}
5268 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5269 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns, as a number of minutes, the
5270 @Chg{Version=[5],New=[Time_Offset of],Old=[@Chg{Version=[3],New=[result of
5271 subtracting],Old=[difference between]}]}
5272 the implementation-defined time zone of
5273 Calendar@Chg{Version=[5],New=[],Old=[@Chg{Version=[3],New=[ from],Old=[, and]}
5274 UTC time]}, at the time Date. If the time zone of the Calendar implementation is
5275 unknown, then Unknown_Zone_Error is raised.]}
5276 @begin{Ramification}
5277 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0119-1]}
5278 @ChgAdded{Version=[3],Text=[In North America, the result will be negative;
5279 in Europe, the result will be zero or positive.]}
5280 @end{Ramification}
5281 @begin{Discussion}
5282 @ChgRef{Version=[2],Kind=[AddedNormal]}
5283 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5284 @ChgAdded{Version=[2],Text=[The Date parameter is needed to take
5285 into account time differences caused by daylight-savings time and other
5286 time changes.@Chg{Version=[5],New=[],Old=[ This parameter is measured in
5287 the time zone of Calendar, if any, not necessarily the UTC time zone.]}]}
5288
5289 @ChgRef{Version=[2],Kind=[AddedNormal]}
5290 @ChgAdded{Version=[2],Text=[Other time zones can be supported with a
5291 child package. We don't define one because of the lack of agreement
5292 on the definition of a time zone.]}
5293
5294 @ChgRef{Version=[2],Kind=[AddedNormal]}
5295 @ChgAdded{Version=[2],Text=[The accuracy of this routine is not specified;
5296 the intent is that the facilities of the underlying target operating system
5297 are used to implement it.]}
5298 @end{Discussion}
5299
5300 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5301 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<procedure> Difference (Left, Right : @key<in> Time;
5302 Days : @key<out> Day_Count;
5303 Seconds : @key<out> Duration;
5304 Leap_Seconds : @key<out> Leap_Seconds_Count);]}
5305 @end{Example}
5306 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5307 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the difference between
5308 Left and Right. Days is the number of days of difference, Seconds is the
5309 remainder seconds of difference excluding leap seconds, and Leap_Seconds is
5310 the number of leap seconds. If Left < Right, then Seconds <= 0.0, Days <= 0,
5311 and Leap_Seconds <= 0. Otherwise, all values are nonnegative.
5312 The absolute value of Seconds is always less than 86_400.0.
5313 For the returned values, if Days =
5314 0, then Seconds + Duration(Leap_Seconds) = Calendar."@en" (Left, Right).]}
5315 @begin{Discussion}
5316 @ChgRef{Version=[2],Kind=[AddedNormal]}
5317 @ChgAdded{Version=[2],Text=[Leap_Seconds, if any, are not included in
5318 Seconds. However, Leap_Seconds should be included in calculations
5319 using the operators defined in Calendar, as is specified for "@en" above.]}
5320 @end{Discussion}
5321
5322
5323 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5324 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> "+" (Left : Time; Right : Day_Count) @key<return> Time;
5325 @key<function> "+" (Left : Day_Count; Right : Time) @key<return> Time;]}
5326 @end{Example}
5327 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5328 @ChgAdded{Version=[2],Type=[Trailing],Text=[Adds a number of days to a time value.
5329 Time_Error is raised if the result is not representable as a value of type
5330 Time.]}
5331
5332 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5333 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> "-" (Left : Time; Right : Day_Count) @key<return> Time;]}
5334 @end{Example}
5335 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5336 @ChgAdded{Version=[2],Type=[Trailing],Text=[Subtracts a number of days from a time value.
5337 Time_Error is raised if the result is not representable as a value of type
5338 Time.]}
5339
5340 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5341 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> "-" (Left, Right : Time) @key<return> Day_Count;]}
5342 @end{Example}
5343 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5344 @ChgAdded{Version=[2],Type=[Trailing],Text=[Subtracts two time values, and returns the
5345 number of days between them. This is the same value that Difference would
5346 return in Days.]}
5347
5348 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5349 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Day_of_Week (Date : Time) @key<return> Day_Name;]}
5350 @end{Example}
5351 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5352 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the day of the week for Time. This is
5353 based on the Year, Month, and Day values of Time.]}
5354
5355 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5356 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Year (Date : Time;
5357 Time_Zone : Time_Zones.Time_Offset := 0)
5358 @key<return> Year_Number;]}
5359 @end{Example}
5360 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00427-01]}
5361 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the year for Date, as
5362 appropriate for the specified time zone offset.]}
5363
5364 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5365 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Month (Date : Time;
5366 Time_Zone : Time_Zones.Time_Offset := 0)
5367 @key<return> Month_Number;]}
5368 @end{Example}
5369 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00427-01]}
5370 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the month for Date, as
5371 appropriate for the specified time zone offset.]}
5372
5373 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5374 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Day (Date : Time;
5375 Time_Zone : Time_Zones.Time_Offset := 0)
5376 @key<return> Day_Number;]}
5377 @end{Example}
5378 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00427-01]}
5379 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the day number for Date, as
5380 appropriate for the specified time zone offset.]}
5381
5382 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5383 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Hour (Date : Time;
5384 Time_Zone : Time_Zones.Time_Offset := 0)
5385 @key<return> Hour_Number;]}
5386 @end{Example}
5387 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5388 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the hour for Date, as appropriate for
5389 the specified time zone offset.]}
5390
5391 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5392 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Minute (Date : Time;
5393 Time_Zone : Time_Zones.Time_Offset := 0)
5394 @key<return> Minute_Number;]}
5395 @end{Example}
5396 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5397 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the minute within the hour for Date,
5398 as appropriate for the specified time zone offset.]}
5399
5400 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5401 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Second (Date : Time)
5402 @key<return> Second_Number;]}
5403 @end{Example}
5404 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5405 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the second within the hour and minute
5406 for Date.]}
5407
5408 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5409 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Sub_Second (Date : Time)
5410 @key<return> Second_Duration;]}
5411 @end{Example}
5412 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5413 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns the fraction of second for
5414 Date (this has the same accuracy as Day_Duration). The value returned is always
5415 less than 1.0.]}
5416
5417 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5418 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Seconds_Of (Hour : Hour_Number;
5419 Minute : Minute_Number;
5420 Second : Second_Number := 0;
5421 Sub_Second : Second_Duration := 0.0)
5422 @key<return> Day_Duration;]}
5423 @end{Example}
5424 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5425 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a Day_Duration value for
5426 the combination of the given Hour, Minute, Second, and Sub_Second.
5427 This value can be used in Calendar.Time_Of as
5428 well as the argument to Calendar."+" and Calendar."@en". If Seconds_Of is
5429 called with a Sub_Second value of 1.0, the value returned is equal to the value
5430 of Seconds_Of for the next second with a Sub_Second value of 0.0.]}
5431
5432 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5433 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<procedure> Split (Seconds : @key<in> Day_Duration;
5434 Hour : @key<out> Hour_Number;
5435 Minute : @key<out> Minute_Number;
5436 Second : @key<out> Second_Number;
5437 Sub_Second : @key<out> Second_Duration);]}
5438 @end{Example}
5439 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5440 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0238-1]}
5441 @ChgAdded{Version=[2],Type=[Trailing],Text=[Splits Seconds into Hour, Minute,
5442 Second and Sub_Second in such a way that the resulting values all belong to
5443 their respective subtypes. The value returned in the Sub_Second
5444 parameter is always less than 1.0.@Chg{Version=[3],New=[ If Seconds = 86400.0,
5445 Split propagates Time_Error.],Old=[]}]}
5446
5447 @begin{Ramification}
5448 @ChgRef{Version=[2],Kind=[AddedNormal]}
5449 @ChgAdded{Version=[2],Text=[There is only one way to do the split which
5450 meets all of the requirements.]}
5451 @end{Ramification}
5452
5453 @begin{Reason}
5454 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0238-1]}
5455 @ChgAdded{Version=[3],Text=[If Seconds = 86400.0, one of the returned values
5456 would have to be out of its defined range (either Sub_Second = 1.0 or Hour =
5457 24 with the other value being 0). This doesn't seem worth breaking the
5458 invariants.]}
5459 @end{Reason}
5460
5461 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5462 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Time_Of (Year : Year_Number;
5463 Month : Month_Number;
5464 Day : Day_Number;
5465 Hour : Hour_Number;
5466 Minute : Minute_Number;
5467 Second : Second_Number;
5468 Sub_Second : Second_Duration := 0.0;
5469 Leap_Second: Boolean := False;
5470 Time_Zone : Time_Zones.Time_Offset := 0)
5471 @key<return> Time;]}
5472 @end{Example}
5473 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5474 @ChgAdded{Version=[2],Type=[Trailing],Text=[If Leap_Second is False,
5475 returns a Time built from the date and time
5476 values, relative to the specified time zone offset. If Leap_Second is True,
5477 returns the Time that represents the time within the leap second that is one
5478 second later than the time specified by the other parameters.
5479 Time_Error is raised if the parameters do not form a proper date or time.
5480 If Time_Of is called with a Sub_Second value of 1.0, the value
5481 returned is equal to the value of Time_Of for the next second with
5482 a Sub_Second value of 0.0.]}
5483 @begin{Discussion}
5484 @ChgRef{Version=[2],Kind=[AddedNormal]}
5485 @ChgAdded{Version=[2],Text=[Time_Error should be raised if Leap_Second
5486 is True, and the date and time values do not represent the second before
5487 a leap second. A leap second always occurs at midnight UTC,
5488 and is 23:59:60 UTC in ISO notation. So, if the time zone is UTC and
5489 Leap_Second is True, if any of Hour /= 23, Minute /= 59, or Second /= 59,
5490 then Time_Error should be raised.
5491 However, we do not say that, because other time zones will have different
5492 values where a leap second is allowed.]}
5493 @end{Discussion}
5494
5495 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5496 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Time_Of (Year : Year_Number;
5497 Month : Month_Number;
5498 Day : Day_Number;
5499 Seconds : Day_Duration := 0.0;
5500 Leap_Second: Boolean := False;
5501 Time_Zone : Time_Zones.Time_Offset := 0)
5502 @key<return> Time;]}
5503 @end{Example}
5504 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5505 @ChgAdded{Version=[2],Type=[Trailing],Text=[If Leap_Second is False, returns
5506 a Time built from the date and time
5507 values, relative to the specified time zone offset. If Leap_Second is True,
5508 returns the Time that represents the time within the leap second that is one
5509 second later than the time specified by the other parameters.
5510 Time_Error is raised if the parameters do not form a proper date or time.
5511 If Time_Of is called with a Seconds value of 86_400.0, the value
5512 returned is equal to the value of Time_Of for the next day with
5513 a Seconds value of 0.0.]}
5514
5515 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5516 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<procedure> Split (Date : @key<in> Time;
5517 Year : @key<out> Year_Number;
5518 Month : @key<out> Month_Number;
5519 Day : @key<out> Day_Number;
5520 Hour : @key<out> Hour_Number;
5521 Minute : @key<out> Minute_Number;
5522 Second : @key<out> Second_Number;
5523 Sub_Second : @key<out> Second_Duration;
5524 Leap_Second: @key<out> Boolean;
5525 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5526 @end{Example}
5527 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5528 @ChgAdded{Version=[2],Type=[Trailing],Text=[If Date does not represent a time
5529 within a leap second, splits Date into its constituent parts (Year, Month, Day,
5530 Hour, Minute, Second, Sub_Second), relative to the specified time zone offset,
5531 and sets Leap_Second to False. If Date represents a time within a leap second,
5532 set the constituent parts to values corresponding to a time one second earlier
5533 than that given by Date, relative to the specified time zone offset, and sets
5534 Leap_Seconds to True. The value returned in the Sub_Second parameter is always
5535 less than 1.0.]}
5536
5537 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5538 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<procedure> Split (Date : @key<in> Time;
5539 Year : @key<out> Year_Number;
5540 Month : @key<out> Month_Number;
5541 Day : @key<out> Day_Number;
5542 Hour : @key<out> Hour_Number;
5543 Minute : @key<out> Minute_Number;
5544 Second : @key<out> Second_Number;
5545 Sub_Second : @key<out> Second_Duration;
5546 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5547 @end{Example}
5548 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5549 @ChgAdded{Version=[2],Type=[Trailing],Text=[Splits Date into its constituent parts (Year,
5550 Month, Day, Hour, Minute, Second, Sub_Second), relative to the specified time
5551 zone offset. The value returned in the Sub_Second parameter is always less
5552 than 1.0.]}
5553
5554 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5555 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<procedure> Split (Date : @key<in> Time;
5556 Year : @key<out> Year_Number;
5557 Month : @key<out> Month_Number;
5558 Day : @key<out> Day_Number;
5559 Seconds : @key<out> Day_Duration;
5560 Leap_Second: @key<out> Boolean;
5561 Time_Zone : @key<in> Time_Zones.Time_Offset := 0);]}
5562 @end{Example}
5563 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00427-01]}
5564 @ChgAdded{Version=[2],Type=[Trailing],Text=[If Date does not represent a time
5565 within a leap second, splits Date into its constituent parts (Year, Month, Day,
5566 Seconds), relative to the specified time zone offset, and sets Leap_Second to
5567 False. If Date represents a time within a leap second, set the constituent
5568 parts to values corresponding to a time one second earlier than that given by
5569 Date, relative to the specified time zone offset, and sets Leap_Seconds to
5570 True. The value returned in the Seconds parameter is always less than 86_400.0.]}
5571
5572 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5573 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Image (Date : Time;
5574 Include_Time_Fraction : Boolean := False;
5575 Time_Zone : Time_Zones.Time_Offset := 0) @key<return> String;]}
5576 @end{Example}
5577 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5578 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a string form of the Date relative to
5579 the given Time_Zone.
5580 The format is "Year-Month-Day Hour:Minute:Second", where the Year is a
5581 4-digit value, and all others are 2-digit values, of the functions
5582 defined in Calendar and Calendar.Formatting, including a leading zero,
5583 if needed. The separators between the values are
5584 a minus, another minus, a colon, and a single space between the Day and Hour.
5585 If Include_Time_Fraction is True, the integer part of Sub_Seconds*100 is
5586 suffixed to the string as a point followed by a 2-digit value.]}
5587 @begin{Discussion}
5588 @ChgRef{Version=[2],Kind=[AddedNormal]}
5589 @ChgAdded{Version=[2],Text=[The Image provides a string in ISO 8601 format, the
5590 international standard time format. Alternative representations allowed
5591 in ISO 8601 are not supported here.]}
5592
5593 @ChgRef{Version=[2],Kind=[AddedNormal]}
5594 @ChgAdded{Version=[2],Text=[ISO 8601 allows 24:00:00 for midnight; and a seconds
5595 value of 60 for leap seconds. These are not allowed here (the routines
5596 mentioned above cannot produce those results).]}
5597 @end{Discussion}
5598
5599 @begin{Ramification}
5600 @ChgRef{Version=[2],Kind=[AddedNormal]}
5601 @ChgAdded{Version=[2],Text=[The fractional part is truncated, not rounded.
5602 It would be quite hard to define the result with proper rounding, as it can
5603 change all of the values of the image. Values can be rounded up by adding
5604 an appropriate constant (0.5 if Include_Time_Fraction is False,
5605 0.005 otherwise) to the time before taking the image.]}
5606 @end{Ramification}
5607
5608 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5609 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Value (Date : String;
5610 Time_Zone : Time_Zones.Time_Offset := 0) @key<return> Time;]}
5611 @end{Example}
5612 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5613 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a Time value for the image given as
5614 Date, relative to the given time zone. Constraint_Error is raised if the string
5615 is not formatted as described for Image, or the function cannot interpret the
5616 given string as a Time value.]}
5617
5618 @begin{Discussion}
5619 @ChgRef{Version=[2],Kind=[AddedNormal]}
5620 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
5621 @ChgAdded{Version=[2],Text=[The intent is that the implementation
5622 enforce the same range rules on the string as the appropriate function
5623 Time_Of, except for the hour, so
5624 @lquotes@;cannot interpret the given string as a Time value@rquotes
5625 happens when one of the values is out of the required range.
5626 For example, "2005-08-31 @Chg{Version=[3],New=[24:00:00],Old=[24:0:0]}"
5627 should raise Constraint_Error (the hour is out of range).]}
5628 @end{Discussion}
5629
5630 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5631 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Image (Elapsed_Time : Duration;
5632 Include_Time_Fraction : Boolean := False) @key<return> String;]}
5633 @end{Example}
5634 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5635 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a string form of the Elapsed_Time.
5636 The format is "Hour:Minute:Second", where all values are
5637 2-digit values, including a leading zero, if needed.
5638 The separators between the values are colons.
5639 If Include_Time_Fraction is True, the integer part of Sub_Seconds*100 is
5640 suffixed to the string as a point followed by a 2-digit value.
5641 If Elapsed_Time < 0.0, the result is Image (@key<abs> Elapsed_Time,
5642 Include_Time_Fraction) prefixed with a minus sign. If @key<abs> Elapsed_Time
5643 represents 100 hours or more, the result is implementation-defined.]}
5644 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5645 Text=[The result of Calendar.Formating.Image if its argument represents more
5646 than 100 hours.]}]}
5647 @begin{ImplNote}
5648 @ChgRef{Version=[2],Kind=[AddedNormal]}
5649 @ChgAdded{Version=[2],Text=[This cannot be implemented (directly) by calling
5650 Calendar.Formatting.Split, since it may be out of the range of
5651 Day_Duration, and thus the number of hours may be out of the range of
5652 Hour_Number.]}
5653
5654 @ChgAdded{Version=[2],Text=[If a Duration value can represent more then 100 hours,
5655 the implementation will need to define a format for the return of Image.]}
5656 @end{ImplNote}
5657
5658 @begin{Example}@ChgRef{Version=[2],Kind=[AddedNormal]}
5659 @ChgAdded{Version=[2],Keepnext=[T],Text=[@key<function> Value (Elapsed_Time : String) @key<return> Duration;]}
5660 @end{Example}
5661 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5662 @ChgAdded{Version=[2],Type=[Trailing],Text=[Returns a Duration value for the image given
5663 as Elapsed_Time. Constraint_Error is raised if the string is not formatted as
5664 described for Image, or the function cannot interpret the given string as a
5665 Duration value.]}
5666 @begin{Discussion}
5667 @ChgRef{Version=[2],Kind=[AddedNormal]}
5668 @ChgAdded{Version=[2],Text=[The intent is that the implementation
5669 enforce the same range rules on the string as the appropriate function
5670 Time_Of, except for the hour, so
5671 @lquotes@;cannot interpret the given string as a Time value@rquotes
5672 happens when one of the values is out of the required range.
5673 For example, "10:23:60" should raise Constraint_Error (the seconds value
5674 is out of range).]}
5675 @end{Discussion}
5676
5677
5678 @end{DescribeCode}
5679
5680 @end{StaticSem}
5681
5682 @begin{ImplAdvice}
5683 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5684 @ChgAdded{Version=[2],Text=[An implementation should support leap seconds if the
5685 target system supports them. If leap seconds are not supported, Difference
5686 should return zero for Leap_Seconds, Split should return False for Leap_Second,
5687 and Time_Of should raise Time_Error if Leap_Second is True.]}
5688 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
5689 Text=[Leap seconds should be supported if the target system supports them.
5690 Otherwise, operations in Calendar.Formatting should return results
5691 consistent with no leap seconds.]}]}
5692 @begin{Discussion}
5693 @ChgRef{Version=[2],Kind=[AddedNormal]}
5694 @ChgAdded{Version=[2],Text=[An implementation can always support leap seconds
5695 when the target system does not; indeed, this isn't particularly
5696 hard (all that is required is a table of when leap seconds were inserted). As
5697 such, leap second support isn't @lquotes@;impossible or impractical@rquotes
5698 in the sense of @RefSecNum{Conformity of an Implementation with the Standard}.
5699 However, for some purposes, it may be important to follow the target system's
5700 lack of leap second support (if the target is a GPS satellite, which does not
5701 use leap seconds, leap second support would be a handicap to work around).
5702 Thus, this @ImplAdviceTitle should be read as giving permission to not support
5703 leap seconds on target systems that don't support leap seconds. Implementers
5704 should use the needs of their customers to determine whether or not support
5705 leap seconds on such targets.]}
5706 @end{Discussion}
5707 @end{ImplAdvice}
5708
5709 @begin{Notes}
5710 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5711 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5712 @ChgAdded{Version=[2],Text=[The implementation-defined time zone of package Calendar
5713 may, but need not, be the local time zone.
5714 @Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]} always returns the
5715 difference relative to the implementation-defined time zone of package
5716 Calendar. If @Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]}
5717 does not raise Unknown_Zone_Error, UTC time
5718 can be safely calculated (within the accuracy of the underlying time-base).]}
5719
5720 @begin{Discussion}
5721 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5722 @ChgAdded{Version=[2],Text=[The time in the time zone known as Greenwich
5723 Mean Time (GMT) is generally very close to UTC time; for most purposes they
5724 can be treated the same. GMT is the time based on the rotation of the Earth;
5725 UTC is the time based on atomic clocks, with leap seconds periodically
5726 inserted to realign with GMT (because most human activities depend on the
5727 rotation of the Earth). At any point in time, there will be a sub-second
5728 difference between GMT and UTC.]}
5729 @end{Discussion}
5730
5731 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01]}
5732 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5733 @ChgAdded{Version=[2],Text=[Calling Split on the results of subtracting
5734 Duration(@Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]}*60)
5735 from Clock provides the components (hours,
5736 minutes, and so on) of the UTC time. In the United States, for example,
5737 @Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]} will generally
5738 be negative.]}
5739 @begin{Discussion}
5740 @ChgRef{Version=[2],Kind=[AddedNormal]}
5741 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0336-1]}
5742 @ChgAdded{Version=[2],Text=[This is an illustration to help specify the value of
5743 @Chg{Version=[5],New=[Local_Time_Offset],Old=[UTC_Time_Offset]}. A user
5744 should pass @Chg{Version=[5],New=[zero],Old=[UTC_Time_Offset]} as the Time_Zone
5745 parameter of Split, rather than trying to make the above calculation.]}
5746 @end{Discussion}
5747 @end{Notes}
5748
5749 @begin{Extend95}
5750 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00351-01],ARef=[AI95-00428-01]}
5751 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
5752 Packages Calendar.Time_Zones, Calendar.Arithmetic, and Calendar.Formatting
5753 are new.]}
5754 @end{Extend95}
5755
5756 @begin{Inconsistent2005}
5757 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0238-1]}
5758 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005}@b<Correction:>
5759 Defined that Split for Seconds raises Time_Error for a value of exactly
5760 86400.0, rather than breaking some invariant or raising some other exception.
5761 Ada 2005 left this unspecified; a program that depended on what some
5762 implementation does might break, but such a program is not portable anyway.]}
5763 @end{Inconsistent2005}
5764
5765 @begin{Diffword2005}
5766 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0119-1]}
5767 @ChgAdded{Version=[3],Text=[@b<Correction:> Clarified the sign of
5768 UTC_Time_Offset.]}
5769 @end{Diffword2005}
5770
5771 @begin{Inconsistent2012}
5772 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0336-1]}
5773 @ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2012}@b<Correction:>
5774 Changed the definition of Time_Offset to be compatible with most compilers.
5775 Also added Local_Time_Offset and Local_Image to better describe the intent.
5776 A program that expects the Ada 2012 definition of Time_Offset would get
5777 incorrect answers. However, most compilers tested use the revised definition,
5778 so the likelihood of a program breaking is quite low.]}
5779 @end{Inconsistent2012}
5780
5781
5782 @LabeledClause{Select Statements}
5783
5784 @begin{Intro}
5785 @redundant[There are four forms of the @nt{select_statement}. One form provides a
5786 selective wait for one or more @nt{select_alternative}s. Two provide
5787 timed and conditional entry calls. The fourth provides asynchronous
5788 transfer of control.]
5789 @end{Intro}
5790
5791 @begin{Syntax}
5792 @Syn{lhs=<select_statement>,rhs="
5793 @Syn2{selective_accept}
5794 | @Syn2{timed_entry_call}
5795 | @Syn2{conditional_entry_call}
5796 | @Syn2{asynchronous_select}"}
5797 @end{Syntax}
5798
5799 @begin{Examples}
5800 @leading@keepnext@i{Example of a select statement:}
5801 @begin{Example}
5802 @key(select)
5803 @key(accept) Driver_Awake_Signal;
5804 @key(or)
5805 @key(delay) 30.0*Seconds;
5806 Stop_The_Train;
5807 @key(end) @key(select);
5808 @end{Example}
5809 @end{Examples}
5810
5811 @begin{Extend83}
5812 @Defn{extensions to Ada 83}
5813 @nt{Asynchronous_select} is new.
5814 @end{Extend83}
5815
5816 @LabeledSubClause{Selective Accept}
5817
5818 @begin{Intro}
5819 @redundant[This form of the @nt{select_statement} allows a combination of waiting for,
5820 and selecting from, one or more alternatives. The
5821 selection may depend on conditions associated with each alternative of the
5822 @nt{selective_accept}.
5823 @IndexSee{Term=[time-out],See=(selective_accept)}]
5824 @end{Intro}
5825
5826 @begin{Syntax}
5827 @Syn{lhs=<selective_accept>,rhs="
5828 @key{select}
5829 [@Syn2{guard}]
5830 @Syn2{select_alternative}
5831 { @key{or}
5832 [@Syn2{guard}]
5833 @Syn2{select_alternative} }
5834 [ @key{else}
5835 @Syn2{sequence_of_statements} ]
5836 @key{end select};"}
5837
5838 @Syn{lhs=<guard>,rhs="@key{when} @Syn2{condition} =>"}
5839
5840
5841 @Syn{lhs=<select_alternative>,rhs="
5842 @Syn2{accept_alternative}
5843 | @Syn2{delay_alternative}
5844 | @Syn2{terminate_alternative}"}
5845
5846
5847 @Syn{lhs=<accept_alternative>,rhs="
5848 @Syn2{accept_statement} [@Syn2{sequence_of_statements}]"}
5849
5850 @Syn{lhs=<delay_alternative>,rhs="
5851 @Syn2{delay_statement} [@Syn2{sequence_of_statements}]"}
5852
5853 @Syn{lhs=<terminate_alternative>,rhs="@key{terminate};"}
5854
5855 @begin(SyntaxText)
5856 @leading@;A @nt{selective_accept} shall contain at least one @nt{accept_alternative}.
5857 In addition, it can contain:
5858 @begin{itemize}
5859 a @nt{terminate_alternative} (only one); or
5860
5861 one or more @nt{delay_alternative}s; or
5862
5863 @Defn2{Term=[else part], Sec=(of a @nt<selective_accept>)}
5864 an @i(else part) (the reserved word @key(else) followed
5865 by a @nt<sequence_of_statements>).
5866 @end{itemize}
5867
5868 These three possibilities are mutually exclusive.
5869 @end(SyntaxText)
5870 @end{Syntax}
5871
5872 @begin{Legality}
5873
5874 If a @nt{selective_accept} contains more than one @nt{delay_alternative},
5875 then all shall be @nt<delay_@!relative_@!statement>s,
5876 or all shall be @nt<delay_@!until_@!statement>s for the same time type.
5877 @begin{Reason}
5878 This simplifies the implementation and the description of the semantics.
5879 @end{Reason}
5880
5881 @end{Legality}
5882
5883 @begin{RunTime}
5884
5885 @Defn{open alternative}
5886 A @nt<select_alternative> is said to be @i(open) if
5887 it is not immediately preceded by a @nt<guard>, or if
5888 the @nt<condition> of its @nt<guard> evaluates to True. It
5889 is said to be @i(closed) otherwise.
5890
5891 @PDefn2{Term=[execution], Sec=(selective_accept)}
5892 For the execution of a @nt{selective_accept}, any @nt{guard}
5893 @nt{condition}s are evaluated; open alternatives are
5894 thus determined. For an open @nt{delay_alternative}, the
5895 @i(delay_)@nt<expression> is also evaluated. Similarly, for an open
5896 @nt{accept_alternative} for
5897 an entry of a family, the @nt{entry_index} is also evaluated.
5898 These evaluations are performed in an arbitrary order, except that
5899 a @i(delay_)@nt<expression> or @nt<entry_index> is not evaluated until
5900 after evaluating the corresponding @nt<condition>, if any.
5901 Selection and execution of one open alternative, or of the else part, then
5902 completes the execution of the @nt{selective_accept}; the rules for
5903 this selection are described below.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
5904
5905 Open @nt{accept_alternative}s are first considered. Selection of one such
5906 alternative takes place immediately if the corresponding
5907 entry already has queued calls. If several alternatives
5908 can thus be selected, one of them is selected according to the
5909 entry queuing policy in effect (see @RefSecNum(Entry Calls) and
5910 @RefSecNum(Entry Queuing Policies)).
5911 When such an
5912 alternative is selected, the selected call is
5913 removed from its entry queue and the @nt<handled_sequence_of_@!statements>
5914 (if any) of the corresponding @nt{accept_statement} is executed; after the
5915 rendezvous completes any subsequent @nt<sequence_of_@!statements>
5916 of the alternative is executed.
5917 @PDefn2{Term=[blocked], Sec=(execution of a @nt<selective_accept>)}
5918 If no selection is immediately possible (in the above sense)
5919 and there is no else part, the task
5920 blocks until an open alternative can be selected.
5921
5922 @leading@;Selection of the other forms of alternative or of an else part is performed
5923 as follows:
5924 @begin{itemize}
5925
5926 An open @nt{delay_alternative} is selected when
5927 its expiration time is reached if no @nt{accept_@!alternative}
5928 or other @nt<delay_@!alternative> can be selected prior to the
5929 expiration time. If several
5930 @nt{delay_@!alternative}s have this same expiration time,
5931 one of them is selected according to the queuing policy in
5932 effect (see @RefSecNum{Entry Queuing Policies}); the default queuing
5933 policy chooses arbitrarily among the @nt<delay_@!alternative>s
5934 whose expiration time has passed.
5935
5936 The else part is selected and its @nt<sequence_of_@!statements> is executed
5937 if no @nt{accept_alternative} can immediately be selected;
5938 in particular, if all alternatives are closed.
5939
5940 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
5941 An open @nt{terminate_alternative} is selected if the conditions stated at the
5942 end of @Chg{Version=[3],New=[subclause],Old=[clause]}
5943 @RefSecNum{Task Dependence - Termination of Tasks}
5944 are satisfied.
5945 @begin(Ramification)
5946 In the absence of a @nt<requeue_statement>, the conditions stated
5947 are such that a @nt<terminate_alternative> cannot be selected while
5948 there is a queued entry call for any entry of the task.
5949 In the presence of requeues from a task to one of its subtasks,
5950 it is possible that when a @nt<terminate_alternative> of the
5951 subtask is selected, requeued calls (for closed entries only) might still
5952 be queued on some entry of the subtask. Tasking_Error will
5953 be propagated to such callers, as is usual when a task completes
5954 while queued callers remain.
5955 @end(Ramification)
5956
5957 @end{itemize}
5958
5959 @Defn2{Term=[Program_Error],Sec=(raised by closed alternatives)}
5960 The exception Program_Error is raised if all alternatives are closed and
5961 there is no else part.
5962
5963 @end{RunTime}
5964
5965 @begin{Notes}
5966
5967 A @nt{selective_accept} is allowed to have several open
5968 @nt{delay_alternative}s. A @nt{selective_accept} is allowed
5969 to have several open
5970 @nt{accept_alternative}s for the same entry.
5971
5972 @end{Notes}
5973
5974 @begin{Examples}
5975 @leading@keepnext@i{Example of a task body with a selective accept:}
5976 @begin{Example}
5977 @key(task) @key(body) Server @key(is)
5978 Current_Work_Item : Work_Item;
5979 @key(begin)
5980 @key(loop)
5981 @key(select)
5982 @key(accept) Next_Work_Item(WI : @key(in) Work_Item) @key(do)
5983 Current_Work_Item := WI;
5984 @key(end);
5985 Process_Work_Item(Current_Work_Item);
5986 @key(or)
5987 @key(accept) Shut_Down;
5988 @key(exit); --@RI[ Premature shut down requested]
5989 @key(or)
5990 @key(terminate); --@RI[ Normal shutdown at end of scope]
5991 @key(end) @key(select);
5992 @key(end) @key(loop);
5993 @key(end) Server;
5994 @end{Example}
5995 @end{Examples}
5996
5997 @begin{DiffWord83}
5998 The name of @ntf{selective_wait} was changed to @nt{selective_accept} to
5999 better describe what is being waited for.
6000 We kept @nt{select_alternative} as is, because
6001 @ntf<selective_accept_alternative> was too easily confused
6002 with @nt<accept_alternative>.
6003 @end{DiffWord83}
6004
6005
6006 @LabeledSubClause{Timed Entry Calls}
6007
6008 @begin{Intro}
6009 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6010 @redundant[A @nt{timed_entry_call} issues an entry call that is
6011 cancelled if the call (or a requeue-with-abort of the call)
6012 is not selected before the expiration time is
6013 reached.@Chg{Version=[2],New=[ A procedure call may appear rather than
6014 an entry call for cases where the procedure might be implemented by
6015 an entry.],Old=[]}
6016 @IndexSee{Term=[time-out],See=(timed_entry_call)}]
6017 @end{Intro}
6018
6019 @begin{Syntax}
6020 @Syn{lhs=<timed_entry_call>,rhs="
6021 @key{select}
6022 @Syn2{entry_call_alternative}
6023 @key{or}
6024 @Syn2{delay_alternative}
6025 @key{end select};"}
6026
6027 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6028 @Syn{lhs=<entry_call_alternative>,rhs="
6029 @Chg{Version=[2],New=[@Syn2{procedure_or_entry_call}],Old=[@Syn2{entry_call_statement}]} [@Syn2{sequence_of_statements}]"}
6030
6031 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
6032 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[procedure_or_entry_call],Old=[]}>,rhs="
6033 @Chg{Version=[2],New=[@Syn2{procedure_call_statement} | @Syn2{entry_call_statement}],Old=[]}"}
6034 @end{Syntax}
6035
6036 @begin{Legality}
6037 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
6038 @ChgAdded{Version=[2],Text=[If a @nt{procedure_call_statement} is used for a
6039 @nt{procedure_or_entry_call}, the @SynI{procedure_}@nt{name} or
6040 @SynI{procedure_}@nt{prefix} of the @nt{procedure_call_statement} shall
6041 statically denote an entry renamed as a procedure or (a view of) a
6042 primitive subprogram of a limited interface whose first parameter is a
6043 controlling parameter (see @RefSecNum{Dispatching Operations of Tagged Types}).]}
6044 @begin{Reason}
6045 @ChgRef{Version=[2],Kind=[AddedNormal]}
6046 @ChgAdded{Version=[2],Text=[This would be a confusing way to call a procedure,
6047 so we only allow it when it is possible that the procedure is actually an
6048 entry. We could have allowed formal subprograms here, but we didn't because
6049 we'd have to allow all formal subprograms, and it would increase the
6050 difficulty of generic code sharing.]}
6051
6052 @ChgRef{Version=[2],Kind=[AddedNormal]}
6053 @ChgAdded{Version=[2],Text=[We say @lquotes@;statically denotes@rquotes
6054 because an access-to-subprogram cannot be primitive, and we don't have
6055 anything like access-to-entry. So only names of entries or procedures are
6056 possible.]}
6057 @end{Reason}
6058 @end{Legality}
6059
6060 @begin{StaticSem}
6061 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
6062 @ChgRef{Version=[3],Kind=[DeletedAddedNoDelMsg],ARef=[AI05-0291-1]}@Comment{
6063 We don't need a message here, as this is the last inserted paragraph}
6064 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[If a
6065 @nt{procedure_call_statement} is used for a @nt{procedure_or_entry_call}, and
6066 the procedure is implemented by an entry, then the @SynI{procedure_}@nt{name},
6067 or @SynI{procedure_}@nt{prefix} and possibly the first parameter of the
6068 @nt{procedure_call_statement}, determine the target object of the call and the
6069 entry to be called.]}]}
6070 @begin{Discussion}
6071 @ChgRef{Version=[2],Kind=[AddedNormal]}
6072 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
6073 @ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[The above says @lquotes@;possibly the first
6074 parameter@rquotes@;, because Ada allows entries to be renamed and passed as
6075 formal subprograms. In those cases, the task or protected object is implicit
6076 in the name of the routine; otherwise the object is an explicit parameter to
6077 the call.]}]}
6078 @end{Discussion}
6079 @end{StaticSem}
6080
6081 @begin{RunTime}
6082
6083 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6084 @PDefn2{Term=[execution], Sec=(timed_entry_call)}
6085 For the execution of a @nt{timed_entry_call}, the @SynI(entry_)@nt<name>@Chg{Version=[2],
6086 New=[, @Syni{procedure_}@nt{name}, or @Syni{procedure_}@nt{prefix},],Old=[]}
6087 and any actual parameters are evaluated,
6088 as for a simple entry call (see @RefSecNum(Entry Calls))@Chg{Version=[2],New=[
6089 or procedure call (see @RefSecNum{Subprogram Calls})],Old=[]}.
6090 The expiration time
6091 (see @RefSecNum(Delay Statements, Duration, and Time))
6092 for the call is determined by evaluating
6093 the @i(delay_)@nt<expression> of the
6094 @nt<delay_alternative>@Chg{Version=[2],New=[. If the call is an entry call or
6095 a call on a procedure implemented by an entry,],Old=[;]}
6096 the entry call is then issued.@Chg{Version=[2],New=[ Otherwise, the call
6097 proceeds as described in @RefSecNum{Subprogram Calls} for a procedure call,
6098 followed by the @nt{sequence_of_@!statements} of the @nt{entry_call_@!alternative};
6099 the @nt{sequence_of_@!statements} of the @nt{delay_@!alternative} is ignored.],Old=[]}
6100
6101
6102 If the call is queued (including due to a requeue-with-abort),
6103 and not selected before the expiration
6104 time is reached, an attempt to cancel the call is made.
6105 If the call completes due to the cancellation, the optional
6106 @nt<sequence_of_@!statements> of the @nt<delay_@!alternative> is
6107 executed; if the entry call completes normally, the optional
6108 @nt<sequence_of_@!statements> of the @nt<entry_call_@!alternative> is
6109 executed.
6110 @begin{Ramification}
6111 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00345-01]}
6112 @ChgDeleted{Version=[2],Text=[The fact that the syntax calls for
6113 an @nt{entry_call_statement} means
6114 that this fact is used in overload resolution.
6115 For example,
6116 if there is a procedure X and an entry X (both with no parameters),
6117 then "select X; ..." is legal,
6118 because overload resolution knows that the entry is the one that was
6119 meant.]}
6120 @end{Ramification}
6121
6122 @end{RunTime}
6123
6124 @begin{Examples}
6125 @leading@keepnext@i{Example of a timed entry call:}
6126 @begin{Example}
6127 @key(select)
6128 Controller.Request(Medium)(Some_Item);
6129 @key(or)
6130 @key(delay) 45.0;
6131 --@RI[ controller too busy, try something else]
6132 @key(end) @key(select);
6133 @end{Example}
6134 @end{Examples}
6135
6136 @begin{DiffWord83}
6137 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6138 This @Chg{Version=[3],New=[subclause],Old=[clause]} comes before the one
6139 for Conditional Entry Calls,
6140 so we can define conditional entry calls in terms of timed entry calls.
6141 @end{DiffWord83}
6142
6143 @begin{Incompatible95}
6144 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
6145 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]}
6146 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
6147 A procedure @Chg{Version=[3],New=[call ],Old=[]}can be used as the
6148 @Chg{Version=[3],New=[@nt{entry_call_alternative} ],Old=[]}in a timed or
6149 conditional entry call, if the procedure
6150 might actually be an entry. Since the fact that something is an entry
6151 could be used in resolving these calls in Ada 95, it is possible for
6152 timed or conditional entry calls that resolved in Ada 95 to be ambiguous
6153 in Ada 2005. That could happen if both an entry and procedure with the
6154 same name and profile exist, which should be rare.]}
6155 @end{Incompatible95}
6156
6157
6158 @LabeledSubClause{Conditional Entry Calls}
6159
6160 @begin{Intro}
6161
6162 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6163 @Redundant[A @nt{conditional_entry_call} issues an entry call that is
6164 then cancelled if it is not selected immediately (or if a requeue-with-abort
6165 of the call is not selected immediately).@Chg{Version=[2],New=[ A procedure
6166 call may appear rather than
6167 an entry call for cases where the procedure might be implemented by
6168 an entry.],Old=[]}]
6169 @begin(Honest)
6170 In the case of an entry call on a protected object, it is OK if the entry
6171 is closed at the start of the corresponding protected action, so long as
6172 it opens and the call is selected before the end of that protected
6173 action (due to changes in the Count attribute).
6174 @end(Honest)
6175
6176 @end{Intro}
6177
6178 @begin{Syntax}
6179 @Syn{lhs=<conditional_entry_call>,rhs="
6180 @key{select}
6181 @Syn2{entry_call_alternative}
6182 @key{else}
6183 @Syn2{sequence_of_statements}
6184 @key{end select};"}
6185 @end{Syntax}
6186
6187 @begin{RunTime}
6188
6189 @PDefn2{Term=[execution], Sec=(conditional_entry_call)}
6190 The execution of a @nt<conditional_entry_call> is defined to be equivalent
6191 to the execution of a @nt<timed_@!entry_@!call> with a @nt<delay_@!alternative>
6192 specifying an immediate expiration time and the
6193 same @nt<sequence_of_@!statements> as given after the reserved word @key(else).
6194 @end{RunTime}
6195
6196 @begin{Notes}
6197
6198 A @nt{conditional_entry_call} may briefly increase the Count attribute of
6199 the entry, even if the conditional call is not selected.
6200
6201 @end{Notes}
6202
6203 @begin{Examples}
6204 @leading@keepnext@i{Example of a conditional entry call:}
6205 @begin{Example}
6206 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
6207 @key(procedure) Spin(R : @key[in] @Chg{Version=[5],New=[@key[out] ],Old=[]}Resource) @key(is)@Chg{Version=[5],New=[ --@RI[ see @RefSecNum{Protected Units and Protected Objects}]],Old=[]}
6208 @key(begin)
6209 @key(loop)
6210 @key(select)
6211 R.Seize;
6212 @key(return);
6213 @key(else)
6214 @key(null); --@RI[ busy waiting]
6215 @key(end) @key(select);
6216 @key(end) @key(loop);
6217 @key(end);
6218 @end{Example}
6219 @end{Examples}
6220
6221 @begin{DiffWord83}
6222 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6223 This @Chg{Version=[3],New=[subclause],Old=[clause]} comes after the
6224 one for Timed Entry Calls, so we can define conditional entry calls in terms of
6225 timed entry calls.
6226 We do that so that an "expiration time" is defined for both,
6227 thereby simplifying the definition of what happens on
6228 a requeue-with-abort.
6229 @end{DiffWord83}
6230
6231
6232 @RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM}
6233 @LabeledSubClause{Asynchronous Transfer of Control}
6234
6235 @begin{Intro}
6236 @redundant[An asynchronous @nt{select_statement} provides
6237 asynchronous transfer of control
6238 upon completion of an entry call or the expiration of a delay.]
6239 @end{Intro}
6240
6241 @begin{Syntax}
6242 @Syn{lhs=<asynchronous_select>,rhs="
6243 @key{select}
6244 @Syn2{triggering_alternative}
6245 @key{then abort}
6246 @Syn2{abortable_part}
6247 @key{end select};"}
6248
6249 @Syn{lhs=<triggering_alternative>,rhs="@Syn2{triggering_statement} [@Syn2{sequence_of_statements}]"}
6250
6251
6252 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6253 @Syn{lhs=<triggering_statement>,rhs="@Chg{Version=[2],New=[@Syn2{procedure_or_entry_call}],Old=[@Syn2{entry_call_statement}]} | @Syn2{delay_statement}"}
6254
6255 @Syn{lhs=<abortable_part>,rhs="@Syn2{sequence_of_statements}"}
6256 @end{Syntax}
6257
6258 @begin{RunTime}
6259
6260 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
6261 @PDefn2{Term=[execution],
6262 Sec=(asynchronous_select with an entry call trigger)}
6263 @Chg{Version=[2],New=[@PDefn2{Term=[execution],
6264 Sec=(asynchronous_select with a procedure call trigger)}],Old=[]}
6265 For the execution of an @nt{asynchronous_select}
6266 whose @nt<triggering_@!statement> is @Chg{Version=[2],
6267 New=[a @nt<procedure_or_entry_call>],Old=[an @nt<entry_call_statement>]},
6268 the @Syni(entry_)@nt<name>@Chg{Version=[2],New=[, @Syni{procedure_}@nt{name},
6269 or @Syni{procedure_}@nt{prefix},],Old=[]} and actual parameters are evaluated
6270 as for a simple entry call (see @RefSecNum(Entry Calls))@Chg{Version=[2],New=[
6271 or procedure call (see @RefSecNum{Subprogram Calls}).
6272 If the call is an entry call or a call on a procedure implemented by an
6273 entry,],Old=[, and]} the entry call is issued.
6274 If the entry call is queued (or requeued-with-abort),
6275 then the @nt<abortable_part> is executed.
6276 @Redundant[If the entry call is selected immediately,
6277 and never requeued-with-abort,
6278 then the @nt<abortable_part> is never started.]@Chg{Version=[2],New=[ If the
6279 call is on a procedure that is not implemented by an entry, the call proceeds
6280 as described in @RefSecNum{Subprogram Calls}, followed by the
6281 @nt{sequence_of_@!statements} of the @nt{triggering_@!alternative}@Redundant[;
6282 the @nt{abortable_part} is never started].],Old=[]}
6283
6284
6285 @PDefn2{Term=[execution],
6286 Sec=(asynchronous_select with a delay_statement trigger)}
6287 For the execution of an @nt<asynchronous_select> whose
6288 @nt<triggering_@!statement> is a @nt<delay_statement>,
6289 the @i(delay_)@nt<expression> is evaluated
6290 and the expiration time is determined,
6291 as for a normal @nt<delay_statement>.
6292 If the expiration time has not already passed, the @nt<abortable_part>
6293 is executed.
6294
6295 If the @nt<abortable_part> completes and is left prior to completion of the
6296 @nt<triggering_@!statement>,
6297 an attempt to cancel the @nt<triggering_@!statement> is made.
6298 If the attempt to cancel succeeds (see @RefSecNum(Entry Calls) and
6299 @RefSecNum(Delay Statements, Duration, and Time)), the
6300 @nt<asynchronous_select> is complete.
6301
6302 If the @nt<triggering_@!statement> completes other than
6303 due to cancellation,
6304 the @nt<abortable_part>
6305 is aborted (if started but not yet completed @em
6306 see @RefSecNum(Abort of a Task - Abort of a Sequence of Statements)).
6307 If the @nt<triggering_@!statement> completes normally, the optional
6308 @nt<sequence_of_@!statements> of the @nt<triggering_@!alternative> is
6309 executed after the @nt<abortable_part> is left.
6310 @begin(Discussion)
6311 We currently don't specify when the by-copy [@key(in)] @key(out)
6312 parameters are assigned back into the actuals. We considered
6313 requiring that to happen after the @nt<abortable_part> is
6314 left. However, that doesn't seem useful enough
6315 to justify possibly overspecifying the implementation approach,
6316 since some of the parameters are passed by reference anyway.
6317
6318 In an earlier description, we required that the @nt<sequence_of_@!statements>
6319 of the @nt<triggering_@!alternative> execute after aborting
6320 the @nt<abortable_part>, but before waiting for it to complete
6321 and finalize, to provide more rapid response to the triggering event
6322 in case the finalization was unbounded. However, various reviewers felt
6323 that this created unnecessary complexity in the description,
6324 and a potential for undesirable concurrency (and nondeterminism)
6325 within a single task. We have now reverted to simpler, more
6326 deterministic semantics,
6327 but anticipate that further discussion of this issue might be
6328 appropriate during subsequent reviews.
6329 One possibility is to leave this area implementation defined,
6330 so as to encourage experimentation. The user would then have
6331 to assume the worst about what kinds of actions are appropriate
6332 for the @nt<sequence_of_@!statements> of the @nt<triggering_@!alternative>
6333 to achieve portability.
6334 @end(Discussion)
6335
6336 @end{RunTime}
6337
6338 @begin{Examples}
6339 @leading@keepnext@Defn2{Term=[signal handling], Sec=(example)}
6340 @Defn2{Term=[interrupt],Sec=(example using @nt<asynchronous_select>)}
6341 @Defn2{Term=[terminal interrupt], Sec=(example)}
6342 @i(Example of a main command loop for a command interpreter:)
6343 @begin(Example)
6344 @key(loop)
6345 @key(select)
6346 Terminal.Wait_For_Interrupt;
6347 Put_Line("Interrupted");
6348 @key(then abort)
6349 -- @RI(This will be abandoned upon terminal interrupt)
6350 Put_Line("-> ");
6351 Get_Line(Command, Last);
6352 Process_Command(Command(1..Last));
6353 @key(end) @key(select);
6354 @key(end) @key(loop);
6355 @end(Example)
6356
6357 @begin{WideAbove}
6358 @leading@keepnext@i(Example of a time-limited calculation:)
6359 @IndexSee{Term=[time-out],See=(asynchronous_select)}
6360 @Defn2{Term=[time-out],Sec=(example)}
6361 @Defn2{Term=[time limit],Sec=(example)}
6362 @Defn2{Term=[interrupt],Sec=(example using @nt<asynchronous_select>)}
6363 @Defn2{Term=[timer interrupt],Sec=(example)}
6364 @end{WideAbove}
6365 @begin(Example)
6366 @key(select)
6367 @key(delay) 5.0;
6368 Put_Line("Calculation does not converge");
6369 @key(then abort)
6370 -- @RI(This calculation should finish in 5.0 seconds;)
6371 -- @RI( if not, it is assumed to diverge.)
6372 Horribly_Complicated_Recursive_Function(X, Y);
6373 @key(end) @key(select);
6374 @end(Example)
6375
6376 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0098-1]}
6377 @ChgAdded{Version=[4],Text=[Note that these examples presume that there are
6378 abort completion points within the execution of the @nt{abortable_part}.]}
6379 @end{Examples}
6380
6381 @begin{Extend83}
6382 @Defn{extensions to Ada 83}
6383 @nt<Asynchronous_select> is new.
6384 @end{Extend83}
6385
6386 @begin{Extend95}
6387 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]}
6388 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
6389 A procedure can be used as the
6390 @nt{triggering_@!statement} of an @nt<asynchronous_select>, if the procedure
6391 might actually be an entry.]}
6392 @end{Extend95}
6393
6394
6395 @LabeledClause{Abort of a Task - Abort of a Sequence of Statements}
6396
6397 @begin{Intro}
6398 @redundant[An @nt{abort_statement} causes one or more tasks to become abnormal, thus
6399 preventing any further interaction with such tasks. The completion
6400 of the @nt<triggering_@!statement> of an @nt<asynchronous_select>
6401 causes a @nt{sequence_of_@!statements} to be aborted.]
6402 @end{Intro}
6403
6404 @begin{Syntax}
6405 @Syn{lhs=<abort_statement>,
6406 rhs="@key{abort} @SynI{task_}@Syn2{name} {, @SynI{task_}@Syn2{name}};"}
6407 @end{Syntax}
6408
6409 @begin{Resolution}
6410
6411 @PDefn2{Term=[expected type], Sec=(abort_statement task_name)}
6412 Each @SynI{task_}@nt{name} is expected to be of any task
6413 type@Redundant[; they need not all be of the same task type.]
6414
6415 @end{Resolution}
6416
6417 @begin{RunTime}
6418
6419 @PDefn2{Term=[execution], Sec=(abort_statement)}
6420 For the execution of an @nt<abort_statement>, the given @i(task_)@nt<name>s
6421 are evaluated in an arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}
6422 @Defn2{Term=[abort], Sec=(of a task)}
6423 @Defn{abnormal task}
6424 @PDefn2{Term=[task state], Sec=(abnormal)}
6425 Each named task is
6426 then @i(aborted), which consists of making the task @i(abnormal)
6427 and aborting the execution of the corresponding @nt<task_body>,
6428 unless it is already completed.
6429 @begin{Ramification}
6430 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
6431 Note that aborting those tasks is not defined to be an
6432 abort-deferred operation.
6433 Therefore, if one of the named tasks is the task executing the
6434 @nt{abort_statement}, or if the task executing the
6435 @nt{abort_statement} depends on one of the named tasks,
6436 then it is possible for the execution of the @nt{abort_statement} to be
6437 aborted, thus leaving some of the tasks unaborted.
6438 This allows the implementation to use either a sequence of calls to an
6439 @lquotes@;abort task@rquotes@; @Chg{Version=[2],New=[run-time
6440 system],Old=[RTS]} primitive, or a single call to an @lquotes@;abort list of
6441 tasks@rquotes@; @Chg{Version=[2],New=[run-time system],Old=[RTS]} primitive.
6442 @end{Ramification}
6443
6444 @leading@PDefn2{Term=[execution], Sec=(aborting the execution of a construct)}
6445 @Defn2{Term=[abort], Sec=(of the execution of a construct)}
6446 When the execution of a construct
6447 is @i(aborted) (including that of a @nt<task_@!body> or of a
6448 @nt<sequence_of_@!statements>), the execution of every construct
6449 included within the aborted execution is also aborted,
6450 except for executions included within the execution of an @i(abort-deferred)
6451 operation; the execution of an abort-deferred operation
6452 continues to completion without being affected by the abort;
6453 @Defn{abort-deferred operation}
6454 the following are the abort-deferred operations:
6455 @begin(Itemize)
6456 a protected action;
6457
6458 waiting for an entry call to complete (after having
6459 initiated the attempt to cancel it @em see below);
6460
6461 waiting for the termination of dependent tasks;
6462
6463 the execution of an Initialize procedure as the last step
6464 of the default initialization of a controlled object;
6465
6466 the execution of a Finalize procedure as part of the
6467 finalization of a controlled object;
6468
6469 an assignment operation to an object with a controlled part.
6470 @end(Itemize)
6471
6472 @Redundant[The last three of these are discussed further in
6473 @RefSecNum(Assignment and Finalization).]
6474 @begin{Reason}
6475 Deferring abort during Initialize and finalization allows,
6476 for example, the result of an allocator performed in
6477 an Initialize operation to be assigned into an access object without
6478 being interrupted in the middle, which would cause storage leaks.
6479 For an object with several controlled parts,
6480 each individual Initialize is abort-deferred.
6481 Note that there is generally no semantic difference between
6482 making each Finalize
6483 abort-deferred, versus making a group of them abort-deferred,
6484 because if the task gets aborted, the first thing it will do is
6485 complete any remaining finalizations.
6486 Individual objects are finalized prior to an assignment operation
6487 (if nonlimited controlled) and as part of Unchecked_Deallocation.
6488 @end{Reason}
6489 @begin(Ramification)
6490 Abort is deferred during the entire assignment operation
6491 to an object with a controlled part,
6492 even if only some subcomponents are controlled.
6493 Note that this says "assignment operation,"
6494 not "@nt{assignment_statement}."
6495 Explicit calls to Initialize, Finalize, or Adjust are
6496 not abort-deferred.
6497 @end(Ramification)
6498
6499
6500 When a master is aborted, all tasks
6501 that depend on that master are aborted.
6502
6503 @PDefn{unspecified}
6504 The order in which tasks become abnormal as the result
6505 of an @nt<abort_statement> or the abort of a @nt<sequence_of_@!statements>
6506 is not specified by the language.
6507
6508 @leading@;If the execution of an entry call is aborted,
6509 an immediate attempt is made to cancel the entry call
6510 (see @RefSecNum(Entry Calls)).
6511 If the execution of a construct
6512 is aborted at a time when the execution is blocked,
6513 other than for an entry call, at a point that is outside
6514 the execution of an abort-deferred operation,
6515 then the execution of the construct completes immediately.
6516 For an abort due to an @nt<abort_statement>,
6517 these immediate effects occur before the execution of
6518 the @nt<abort_statement> completes.
6519 Other than for these immediate cases, the execution
6520 of a construct that is aborted does not necessarily
6521 complete before the @nt<abort_statement> completes.
6522 However, the execution of the aborted construct
6523 completes no later than its next @i(abort completion point) (if any)
6524 that occurs outside of an abort-deferred operation;
6525 @Defn{abort completion point}
6526 the following are abort completion points for an execution:
6527 @begin(Itemize)
6528 the point where the execution initiates the activation of another task;
6529
6530 the end of the activation of a task;
6531
6532 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0119-1]}
6533 @ChgAdded{Version=[5],Text=[a point within a parallel construct where a new
6534 logical thread of control is created;]}
6535
6536 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0119-1]}
6537 @ChgAdded{Version=[5],Text=[the end of a parallel construct;]}
6538
6539 the start or end of the execution of an entry call,
6540 @nt<accept_statement>, @nt<delay_statement>, or @nt<abort_statement>;
6541 @begin(Ramification)
6542 Although the abort completion point doesn't occur until the end
6543 of the entry call or @nt<delay_statement>, these operations might
6544 be cut short because an abort attempts to cancel them.
6545 @end(Ramification)
6546
6547 the start of the execution of a @nt<select_statement>,
6548 or of the @nt<sequence_of_@!statements> of an @nt<exception_handler>.
6549 @begin(Reason)
6550 The start of an @nt<exception_handler> is considered an abort completion
6551 point simply because it is easy for an implementation to check
6552 at such points.
6553 @end(Reason)
6554 @begin(ImplNote)
6555 Implementations may of course check for abort more often than at
6556 each abort completion point; ideally, a fully preemptive
6557 implementation of abort will be provided.
6558 If preemptive abort is not supported in a given environment,
6559 then supporting the checking for abort
6560 as part of subprogram calls and loop iterations might be a useful option.
6561 @end(ImplNote)
6562 @end(Itemize)
6563
6564 @end{RunTime}
6565
6566 @begin{Bounded}
6567 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
6568 @PDefn2{Term=(bounded error),Sec=(cause)}
6569 An attempt to execute an @nt<asynchronous_select> as
6570 part of the execution of an abort-deferred operation is a bounded error.
6571 Similarly, an attempt to create a task that depends on a master
6572 that is included entirely within the execution of
6573 an abort-deferred operation is a bounded error.
6574 @Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}
6575 In both cases, Program_Error is raised if the error is detected
6576 by the implementation; otherwise@Chg{Version=[3],New=[,],Old=[]} the
6577 operations proceed as they would outside an abort-deferred operation, except
6578 that an abort of the @nt<abortable_part>
6579 or the created task might or might not have an effect.
6580 @begin(Reason)
6581 An @nt<asynchronous_select> relies on an abort of the
6582 @nt<abortable_part> to effect the
6583 asynchronous transfer of control. For an @nt<asynchronous_select>
6584 within an abort-deferred operation, the abort might
6585 have no effect.
6586
6587 Creating a task dependent on a master included within an abort-deferred
6588 operation is considered an error, because such tasks could be aborted while
6589 the abort-deferred operation was still progressing, undermining the
6590 purpose of abort-deferral. Alternatively, we could say that such
6591 tasks are abort-deferred for their entire execution, but that seems
6592 too easy to abuse. Note that task creation is already a bounded error
6593 in protected actions, so this additional rule only applies to local task
6594 creation as part of Initialize, Finalize, or Adjust.
6595 @end(Reason)
6596 @end{Bounded}
6597
6598 @begin{Erron}
6599 @PDefn{normal state of an object}
6600 @PDefn{abnormal state of an object}
6601 @Defn{disruption of an assignment}
6602 @PDefn2{Term=(erroneous execution),Sec=(cause)}
6603 If an assignment operation completes prematurely due to an abort,
6604 the assignment is said to be @i{disrupted};
6605 the target of the assignment or its parts can become abnormal,
6606 and certain subsequent uses of the object can be erroneous,
6607 as explained in @RefSecNum{Data Validity}.
6608 @end{Erron}
6609
6610 @begin{Notes}
6611
6612 An @nt{abort_statement} should be used only in situations
6613 requiring unconditional termination.
6614
6615 A task is allowed to abort any task it can name, including itself.
6616
6617 Additional requirements associated with abort
6618 are given in @RefSec(Preemptive Abort).
6619 @end{Notes}
6620
6621 @begin{DiffWord83}
6622 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
6623 This @Chg{Version=[3],New=[subclause],Old=[clause]} has been rewritten to
6624 accommodate the concept
6625 of aborting the execution of a construct, rather than just of a task.
6626 @end{DiffWord83}
6627
6628 @begin{DiffWord2012}
6629 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0119-1]}
6630 @ChgAdded{Version=[5],Text=[Added parallel constructs as abort completion
6631 points.]}
6632 @end{Diffword2012}
6633
6634
6635
6636 @LabeledClause{Task and Entry Attributes}
6637
6638 @begin{RunTime}
6639
6640 @leading@;
6641 For @PrefixType{a @nt<prefix> T that
6642 is of a task type @Redundant[(after
6643 any implicit dereference)]},
6644 the following attributes are defined:
6645 @begin{Description}
6646 @Comment{@ChgAttribute{Version=[2], Kind=[Revised], ChginAnnex=[F], Leading=[F],
6647 Prefix=<T>, AttrName=<Callable>, ARef=[AI95-00345],
6648 Text=<Yields the value True when the task denoted by T
6649 is @i(callable), and False otherwise;>}
6650 @PDefn2{Term=[task state], Sec=(callable)}
6651 @Defn{callable}
6652 a task is callable unless it is completed or abnormal.
6653 The value of this attribute is of the predefined
6654 type Boolean.}
6655 @Attribute{Prefix=<T>, AttrName=<Callable>,
6656 Text=<Yields the value True when the task denoted by T
6657 is @i(callable), and False otherwise;>}
6658 @PDefn2{Term=[task state], Sec=(callable)}
6659 @Defn{callable}
6660 a task is callable unless it is completed or abnormal.
6661 The value of this attribute is of the predefined
6662 type Boolean.
6663
6664 @Attribute{Prefix=<T>, AttrName=<Terminated>,
6665 Text=<Yields the value True if the task denoted by T is
6666 terminated, and False otherwise. The value of this
6667 attribute is of the predefined type Boolean.>}
6668 @end{Description}
6669 @EndPrefixType{}
6670
6671 For @PrefixType{a @nt<prefix> E that denotes an entry
6672 of a task or protected unit},
6673 the following attribute is defined.
6674 This attribute is only allowed within the body of the task or protected
6675 unit, but excluding, in the case of an entry of a task unit, within any
6676 program unit that is, itself, inner to the body of the task unit.
6677 @begin{Description}
6678
6679 @Attribute{Prefix=<E>, AttrName=<Count>,
6680 Text=<Yields the number of calls presently queued on the
6681 entry E of the current instance of the unit.
6682 The value of this attribute is of the type
6683 @i{universal_integer}.>}
6684
6685 @end{Description}
6686 @EndPrefixType{}
6687 @end{RunTime}
6688
6689 @begin{Notes}
6690
6691 For the Count attribute, the entry can be either a single entry or an
6692 entry of a family. The name of the entry or entry
6693 family can be either a @nt<direct_name> or an expanded name.
6694
6695 Within task units, algorithms interrogating the attribute E'Count should
6696 take precautions to allow for the increase of the value of this attribute
6697 for incoming entry calls, and its decrease, for example with
6698 @nt{timed_entry_call}s. Also, a @nt{conditional_entry_call} may briefly
6699 increase this value, even if the conditional call is not accepted.
6700
6701 Within protected units, algorithms interrogating the attribute E'Count
6702 in the @nt<entry_barrier> for the entry E should take precautions to
6703 allow for the evaluation of the @nt<condition> of the barrier both before
6704 and after queuing a given caller.
6705 @end{Notes}
6706
6707
6708
6709 @LabeledClause{Shared Variables}
6710
6711 @begin{StaticSem}
6712 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1],ARef=[AI05-0201-1],ARef=[AI05-0229-1],ARef=[AI05-0295-1]}
6713 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
6714 @Defn2{Term=[shared variable], Sec=(protection of)}
6715 @Defn{independently addressable}
6716 If two different objects, including nonoverlapping
6717 parts of the same object, are @i{independently addressable},
6718 they can be manipulated concurrently by two different
6719 @Chg{Version=[5],New=[logical threads of control],Old=[tasks]} without
6720 synchronization.
6721 @Chg{Version=[3],New=[Any two nonoverlapping objects are independently
6722 addressable if either object is specified as independently addressable (see
6723 @RefSecNum{Shared Variable Control}). Otherwise,
6724 two nonoverlapping objects are independently addressable
6725 except when they are both parts of a composite object for which
6726 a nonconfirming value is specified for any of the following representation
6727 aspects: (record) Layout, Component_Size, Pack, Atomic, or Convention;
6728 in this case it is unspecified whether the parts are independently
6729 addressable.@PDefn{unspecified}],
6730 Old=[Normally, any two
6731 nonoverlapping objects are independently addressable.
6732 However, if packing, record layout, or Component_Size
6733 is specified for a given composite object,
6734 then it is implementation defined whether or not
6735 two nonoverlapping parts of that composite object
6736 are independently addressable.]}
6737 @ChgImplDef{Version=[3],Kind=[Deleted],InitialVersion=[0],
6738 Text=[@Chg{Version=[3],New=[],Old=[Whether or not two
6739 nonoverlapping parts of a composite
6740 object are independently addressable,
6741 in the case where packing, record layout, or Component_Size
6742 is specified for the object.]}]}
6743 @begin{ImplNote}
6744 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6745 Independent addressability is the only high level semantic effect of
6746 @Chg{Version=[3],New=[aspect],Old=[a @nt{pragma}]} Pack.
6747 If two objects are independently addressable,
6748 the implementation should allocate them in such a way
6749 that each can be written by the hardware without writing the other.
6750 For example, unless the user asks for it,
6751 it is generally not feasible to choose a bit-packed
6752 representation on a machine without an atomic bit field
6753 insertion instruction,
6754 because there might be tasks that update neighboring subcomponents
6755 concurrently,
6756 and locking operations on all subcomponents is generally not a good
6757 idea.
6758
6759 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6760 Even if @Chg{Version=[3],New=[Pack],Old=[packing]} or one of the other
6761 above-mentioned aspects is specified, subcomponents should still be updated
6762 independently if the hardware efficiently supports it.
6763 @end{ImplNote}
6764
6765 @begin{Ramification}
6766 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1],ARef=[AI05-0201-1]}
6767 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
6768 @ChgAdded{Version=[3],Text=[An atomic object (including atomic
6769 components) is always independently addressable from any other nonoverlapping
6770 object. @Chg{Version=[4],New=[@nt{Aspect_specification}s and representation
6771 items cannot change that fact],Old=[Any @nt{aspect_specification} or
6772 representation item which would prevent this from being true should be rejected,
6773 notwithstanding what this Standard says elsewhere]}. Note, however, that the
6774 components of an atomic object are not necessarily atomic.]}
6775 @end{Ramification}
6776 @end{StaticSem}
6777
6778 @begin{RunTime}
6779 @leading@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
6780 @redundant[Separate @Chg{Version=[5],New=[logical threads of
6781 control],Old=[tasks]} normally proceed independently and concurrently
6782 with one another. However, task interactions can be used to synchronize
6783 the actions of two or more @Chg{Version=[5],New=[logical threads of
6784 control],Old=[tasks]} to allow, for example, meaningful communication
6785 by the direct updating and reading of variables shared between
6786 @Chg{Version=[5],New=[them],Old=[the tasks]}.]
6787 The actions of two different @Chg{Version=[5],New=[logical threads of
6788 control],Old=[tasks]} are synchronized in this sense when an
6789 action of one @Chg{Version=[5],New=[],Old=[task ]}@i(signals) an action of
6790 the other@Chg{Version=[5],New=[],Old=[ task]};
6791 @Defn2{Term=[signal], Sec=(as defined between actions)}
6792 an action A1 is defined to signal an action A2 under the following
6793 circumstances:
6794 @begin(Itemize)
6795 If A1 and A2 are part of the execution of the same task,
6796 and the language rules require A1 to be performed before A2;
6797
6798 If A1 is the action of an activator that initiates the
6799 activation of a task, and
6800 A2 is part of the execution of the task that is activated;
6801
6802 If A1 is part of the activation of a task, and A2
6803 is the action of
6804 waiting for completion of the activation;
6805
6806 If A1 is part of the execution of a task, and A2 is
6807 the action of waiting for the termination of the task;
6808
6809 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0031],ARef=[AI95-00118-01]}
6810 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0072-1]}
6811 @ChgAdded{Version=[1],Text=[If A1 is the termination of a task T, and A2 is
6812 either @Chg{Version=[3],New=[an],Old=[the]} evaluation of the expression
6813 T'Terminated@Chg{Version=[3],New=[ that results in True,],Old=[]} or
6814 a call to Ada.Task_Identification.Is_Terminated with an actual parameter that
6815 identifies T @Chg{Version=[3],New=[and a result of True ],Old=[]}(see
6816 @RefSecNum(The Package Task_Identification));]}
6817
6818 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0262-1]}
6819 If A1 is the action of issuing an entry call, and A2 is
6820 part of the corresponding execution of the appropriate
6821 @nt<entry_body> or @nt<accept_statement>@Chg{Version=[3],New=[;],Old=[.]}
6822 @begin(Ramification)
6823 Evaluating the @nt<entry_index> of an @nt<accept_statement>
6824 is not synchronized with a corresponding entry call,
6825 nor is evaluating the entry barrier of an @nt<entry_body>.
6826 @end(Ramification)
6827
6828 If A1 is part of the execution of an @nt<accept_statement> or
6829 @nt<entry_body>, and A2 is the action of returning
6830 from the corresponding entry call;
6831
6832 If A1 is part of the execution of a protected procedure body
6833 or @nt<entry_body> for a given protected object, and A2 is part of
6834 a later execution of an @nt<entry_body> for the same
6835 protected object;
6836 @begin(Reason)
6837 The underlying principle here is that
6838 for one action to @lquotes@;signal@rquotes@; a second, the second action has to follow
6839 a potentially blocking operation, whose blocking is dependent on
6840 the first action in some way.
6841 Protected procedures are not potentially blocking, so they can
6842 only be "signalers," they cannot be signaled.
6843 @end(Reason)
6844 @begin(Ramification)
6845 Protected subprogram calls are not defined to signal one another,
6846 which means that such calls alone cannot be used to synchronize
6847 access to shared data outside of a protected object.
6848 @end(Ramification)
6849 @begin(Reason)
6850 The point of this distinction is so that on multiprocessors with
6851 inconsistent caches, the caches only need to be refreshed at
6852 the beginning of an entry body, and forced out at the end of an
6853 entry body or protected procedure that leaves an entry open.
6854 Protected function calls, and protected subprogram calls for
6855 entryless protected objects do not require full cache consistency.
6856 Entryless protected objects are intended to be treated roughly like
6857 atomic objects @em each operation is indivisible with respect to
6858 other operations (unless both are reads), but such operations cannot
6859 be used to synchronize access to other nonvolatile
6860 shared variables.
6861 @end(Reason)
6862
6863 @Leading@Comment{This "Leading" is to help fit the next example on one page.}
6864 If A1 signals some action that in turn signals A2.
6865 @end(Itemize)
6866
6867 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0298-1]}
6868 @ChgAdded{Version=[5],Text=[Action A1 is defined to @i{potentially signal}
6869 action A2 if A1 signals A2, if action A1 and A2 occur as part of the execution
6870 of the same logical thread of control, and the language rules permit
6871 action A1 to precede action A2, or if action A1 potentially signals some
6872 action that in turn potentially signals A2.@Defn{potentially signal}]}
6873
6874 @ChgNote{Prior to Ada 202x (by AI12-0267-1) these two section changes were here
6875 @end{RunTime}
6876
6877 @begin{Erron} -- end ChgNote}
6878
6879 @Leading@ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0267-1]}
6880 @Chg{Version=[5],New=[],Old=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
6881 Given an action of assigning to an object,
6882 and an action of reading or updating a part of the same object
6883 (or of a neighboring object if the two are not
6884 independently addressable), then the execution of the actions is erroneous
6885 unless the actions are
6886 @i(sequential).]}@Defn2{Term=[sequential], Sec=(actions)}@Defn2{Term=(actions),Sec=(sequential)}
6887 Two actions @Chg{Version=[5],New=[are defined to be @i(sequential)],Old=[are
6888 sequential]} if one of the following is true:
6889 @begin(Itemize)
6890 One action signals the other;
6891
6892 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
6893 Both actions occur as part of the execution of the same
6894 @Chg{Version=[5],New=[logical thread of control],Old=[task]};
6895 @begin{Reason}
6896 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
6897 Any two actions of the same @Chg{Version=[5],New=[logical thread of
6898 control],Old=[task]}; are sequential, even if one does not signal the
6899 other because they can be executed in an @lquotes@;arbitrary@rquotes@;
6900 (but necessarily equivalent to some @lquotes@;sequential@rquotes@;) order.
6901 @end{Reason}
6902
6903 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0292-1]}
6904 Both actions occur as part of protected actions on the same protected
6905 object, and at @Chg{Version=[5],New=[least],Old=[most]} one of the actions
6906 is part of a call on @Chg{Version=[5],New=[an exclusive],Old=[a]}
6907 protected @Chg{Version=[5],New=[operation],Old=[function]} of the
6908 protected object.
6909 @begin(Reason)
6910 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0292-1]}
6911 Because actions within protected actions do not always imply
6912 signaling, we have to mention them here explicitly to make sure
6913 that actions occurring within different protected actions of the
6914 same protected object are sequential with respect to one another
6915 (unless both are part of calls on
6916 @Chg{Version=[5],New=[nonexclusive ],Old=[]}protected functions).
6917 @end(Reason)
6918 @begin(Ramification)
6919 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0292-1]}
6920 It doesn't matter whether or not the variable being assigned is
6921 actually a subcomponent of the protected object; globals can be
6922 safely updated from within the bodies of protected
6923 procedures@Chg{Version=[5],New=[, protected],Old=[ or]}
6924 entries@Chg{Version=[5],New=[, or exclusive protected functions],Old=[]}.
6925 @end(Ramification)
6926 @end(Itemize)
6927
6928 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
6929 @Chg{Version=[3],New=[Aspect],Old=[A @nt{pragma}]}
6930 Atomic or @Chg{Version=[3],New=[aspect ],Old=[]}Atomic_Components may also
6931 be @Chg{Version=[3],New=[specified],Old=[used]} to
6932 ensure that certain reads and updates are sequential @em
6933 see @RefSecNum(Shared Variable Control).
6934 @begin(Ramification)
6935 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0119-1]}
6936 If two actions are @lquotes@;sequential@rquotes@; it is known that their executions
6937 don't overlap in time, but it is not necessarily specified which occurs first.
6938 For example, all actions of a single @Chg{Version=[5],New=[logical thread
6939 of control],Old=[task]} are sequential, even though
6940 the exact order of execution is not fully specified for all constructs.
6941 @end(Ramification)
6942 @begin(Discussion)
6943 Note that if two assignments to the same variable are sequential,
6944 but neither signals the other, then the program is not erroneous,
6945 but it is not specified which assignment ultimately prevails.
6946 Such a situation usually corresponds to a programming mistake, but
6947 in some (rare) cases, the order makes no difference, and for this
6948 reason this situation is not considered erroneous nor even a bounded error.
6949 In Ada 83, this was considered an @lquotes@;incorrect order dependence@rquotes@; if
6950 the @lquotes@;effect@rquotes@; of the program was affected, but @lquotes@;effect@rquotes@; was never
6951 fully defined. In Ada 95, this situation represents a potential
6952 nonportability, and a friendly compiler might want to warn the
6953 programmer about the situation, but it is not considered an error.
6954 An example where this would come up would be in gathering statistics
6955 as part of referencing some information, where the assignments
6956 associated with
6957 statistics gathering don't need to be ordered since they are
6958 just accumulating aggregate counts, sums, products, etc.
6959 @end(Discussion)
6960
6961 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
6962 @ChgAdded{Version=[5],Text=[Two actions that are not sequential are defined
6963 to be @i<concurrent> actions.@Defn2{Term=[concurrent], Sec=(actions)}@Defn2{Term=(actions),Sec=(concurrent)}]}
6964
6965 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0298-1]}
6966 @ChgAdded{Version=[5],Text=[Two actions are defined to @i<conflict> if one
6967 action@Defn{conflict}@Defn2{Term=[actions], Sec=(conflicting)} assigns to an
6968 object, and the other action reads or assigns to a part of the same
6969 object (or of a neighboring object if the two are not independently
6970 addressable). The action comprising a call on a subprogram or an
6971 entry is defined to @i{potentially conflict} with another action if the
6972 Global aspect (or Global'Class aspect in the case of a dispatching
6973 call) of the called subprogram or entry is such that a conflicting
6974 action@Defn2{Term=[potentially conflict], Sec=(actions)}@Defn2{Term=[actions], Sec=(potentially conflicting)}@Defn2{Term=[conflict], Sec=(potentially)}
6975 would be possible during the execution of the call. Similarly,
6976 two calls are considered to potentially conflict if they each have
6977 Global (or Global'Class in the case of a dispatching call) aspects
6978 such that conflicting actions would be possible during the execution
6979 of the calls. Finally, two actions that conflict are also considered
6980 to potentially conflict.]}
6981
6982 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
6983 @ChgAdded{Version=[5],Text=[A @i<synchronized> object@Defn{synchronized object}
6984 is an object of a task or protected type, an atomic object (see
6985 @RefSecNum{Shared Variable Control}), a suspension object (see
6986 @RefSecNum{Synchronous Task Control}), or a synchronous barrier (see
6987 @RefSecNum{Synchronous Barriers}). @Redundant[Operations on such objects are
6988 necessarily sequential with respect to one another, and hence are never
6989 considered to conflict.]]}
6990
6991 @ChgNote{Prior to Ada 202x (by AI12-0267-1) this was end{Erron}}
6992 @end{Runtime}
6993
6994 @begin{Erron}@ChgNote{New for Ada 202x}
6995 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
6996 @ChgAdded{Version=[5],Text=[The execution of two concurrent actions is
6997 erroneous@PDefn2{Term=(erroneous execution),Sec=(cause)} if the actions make
6998 conflicting uses of a shared variable (or neighboring variables that are not
6999 independently addressable).]}
7000
7001 @end{Erron}@ChgNote{New for Ada 202x}
7002
7003 @begin{DiffWord95}
7004 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0031],ARef=[AI95-00118-01]}
7005 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that a task T2 can rely on
7006 values of variables that are updated by another task T1, if task T2 first
7007 verifies that T1'Terminated is True.]}
7008 @end{DiffWord95}
7009
7010 @begin{DiffWord2005}
7011 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1],ARef=[AI05-0201-1]}
7012 @ChgAdded{Version=[3],Text=[@b<Correction:> Revised the definition of
7013 independent addressability to exclude conforming representation clauses
7014 and to require that atomic and independent objects always have
7015 independent addressability. This should not change behavior that the
7016 user sees for any Ada program, so it is not an inconsistency.]}
7017
7018 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0072-1]}
7019 @ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording of
7020 AI95-00118-01 to actually say what was intended (as described above).]}
7021 @end{DiffWord2005}
7022
7023 @begin{DiffWord2012}
7024 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0119-1]}
7025 @ChgAdded{Version=[5],Text=[Added wording to support interaction of
7026 parallel constructs with tasks by changing various wording to talk about
7027 logical threads of control rather than purely about tasks.]}
7028
7029 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0298-1]}
7030 @ChgAdded{Version=[5],Text=[Added wording to define potentially signalling
7031 actions and conflicting actions; these are used to define conflict policies.]}
7032 @end{Diffword2012}
7033
7034
7035 @LabeledAddedSubClause{Version=[5],Name=[Conflict Check Policies]}
7036
7037 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7038 @ChgAdded{Version=[5],Text=[This subclause determines what checks are performed
7039 relating to possible concurrent conflicting actions
7040 (see @RefSecNum{Shared Variables}).@Defn{conflict check policy}]}
7041
7042 @begin{Syntax}
7043
7044 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0298-1]}
7045 @ChgAdded{Version=[5],Type=[Leading],Keepnext=[T],Text=[The form of a
7046 @nt{pragma} Conflict_Check_Policy is as follows:]}
7047
7048 @ChgRef{Version=[5],Kind=[AddedNormal]}
7049 @AddedPragmaSyn<Version=[5],@ChgAdded{Version=[5],Text=`@key{pragma} @prag<Conflict_Check_Policy> (@SynI{policy_}@Syn2{identifier}[, @SynI{policy_}@Syn2{identifier}]);'}>
7050
7051 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7052 @ChgAdded{Version=[5],Text=[A @nt{pragma} Conflict_Check_Policy is allowed only
7053 immediately within a @nt{declarative_part}, a @nt{package_specification}, or as
7054 a configuration pragma.]}
7055
7056 @end{Syntax}
7057
7058 @begin{Legality}
7059
7060 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7061 @ChgAdded{Version=[5],Text=[Each @SynI{policy_}@nt{identifier} shall be one of
7062 No_Parallel_Conflict_Checks, Known_Parallel_Conflict_Checks,
7063 All_Parallel_Conflict_Checks, No_Tasking_Conflict_Checks,
7064 Known_Tasking_Conflict_Checks, All_Tasking_Conflict_Checks, No_Conflict_Checks,
7065 Known_Conflict_Checks, All_Conflict_Checks, or an implementation-defined
7066 conflict check policy. If two @SynI{policy_}@nt{identifier}s are given, one
7067 shall include the word Parallel and one shall include the word Tasking. If only
7068 one @SynI{policy_}@nt{identifier} is given, it shall not include the word
7069 Parallel or Tasking.]}
7070
7071 @ChgImplDef{Version=[5],Kind=[Added],Text=[@ChgAdded{Version=[5],
7072 Text=[Implementation-defined conflict check policies.]}]}
7073
7074 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7075 @ChgAdded{Version=[5],Text=[A @nt{pragma} Conflict_Check_Policy given in a
7076 @nt{declarative_part} or immediately within a @nt{package_specification} applies
7077 from the place of the pragma to the end of the innermost enclosing declarative
7078 region. The region for a @nt{pragma} Conflict_Check_Policy given as a configuration
7079 pragma is the declarative region for the entire compilation unit (or units) to
7080 which it applies.]}
7081
7082 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7083 @ChgAdded{Version=[5],Text=[If a @nt{pragma} Conflict_Check_Policy applies to a
7084 @nt{generic_instantiation}, then the @nt{pragma} Conflict_Check_Policy applies
7085 to the entire instance.]}
7086
7087 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0294-1],ARef=[AI12-0298-1]}
7088 @ChgAdded{Version=[5],Text=[If multiple Conflict_Check_Policy pragmas apply to a
7089 given construct, the conflict check policy is determined by the one in the
7090 innermost enclosing region. If no Conflict_Check_Policy pragma applies to a
7091 construct, the policy is (All_Parallel_Conflict_Checks,
7092 No_Tasking_Conflict_Checks) (see below).]}
7093
7094 @begin{Honest}
7095 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0294-1]}
7096 @ChgAdded{Version=[5],Text=[The region mentioned in this rule is the region to
7097 which the policy pragma applies, and not the declarative region in which the
7098 policy pragma appears. This distinction matters when there are multiple policy
7099 pragmas in a single declarative region.]}
7100 @end{Honest}
7101
7102 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0298-1]}
7103 @ChgAdded{Version=[5],Type=[Leading],Text=[Certain potentially conflicting
7104 actions are disallowed according to which conflict check policies apply at the
7105 place where the action or actions occur, as follows:]}
7106
7107 @begin{Description}
7108
7109 @ChgRef{Version=[5],Kind=[AddedNormal]}
7110 @ChgAdded{Version=[5],Text=[No_Parallel_Conflict_Checks@\This policy
7111 imposes no restrictions on concurrent actions arising from
7112 @Defn{No_Parallel_Conflict_Checks conflict check policy}parallel constructs.]}
7113
7114 @ChgRef{Version=[5],Kind=[AddedNormal]}
7115 @ChgAdded{Version=[5],Text=[No_Tasking_Conflict_Checks@\This policy
7116 imposes no restrictions on concurrent actions arising from tasking
7117 @Defn{No_Tasking_Conflict_Checks conflict check policy}constructs.]}
7118
7119 @ChgRef{Version=[5],Kind=[AddedNormal]}
7120 @ChgAdded{Version=[5],Type=[Leading],Text=[Known_Parallel_Conflict_Checks@\If
7121 this policy applies to two concurrent actions appearing within parallel constructs,
7122 @Defn{Known_Parallel_Conflict_Checks conflict check policy}they are disallowed
7123 if they are known to denote the same object (see @RefSecNum{Parameter Associations})
7124 with uses that conflict. For the purposes of this check, any parallel loop may
7125 be presumed to involve multiple concurrent iterations. Also, for the purposes of
7126 deciding whether two actions are concurrent, it is enough for the logical
7127 threads of control in which they occur to be concurrent at any point in their
7128 execution, unless all of the following are true:]}
7129
7130 @begin{Itemize}
7131 @ChgRef{Version=[5],Kind=[AddedNormal]}
7132 @ChgAdded{Version=[5],Text=[the shared object is volatile;]}
7133
7134 @ChgRef{Version=[5],Kind=[AddedNormal]}
7135 @ChgAdded{Version=[5],Text=[the two logical threads of control are both known
7136 to also refer to a shared synchronized object; and]}
7137
7138 @ChgRef{Version=[5],Kind=[AddedNormal]}
7139 @ChgAdded{Version=[5],Text=[each thread whose potentially conflicting action
7140 updates the shared volatile object, also updates this shared synchronized
7141 object.]}
7142
7143 @begin{Reason}
7144 @ChgRef{Version=[5],Kind=[AddedNormal]}
7145 @ChgAdded{Version=[5],Text=[To properly synchronize two actions to prevent
7146 concurrency, a thread that does an update of a volatile object must update
7147 a synchronized object afterward to indicate it has completed its update,
7148 and the other thread needs to test the value of the synchronized object
7149 before it reads the updated volatile object. In a parallel construct,
7150 @ldquote@;signaling@rdquote cannot be used to prevent concurrency,
7151 since that generally requires some blocking, so testing the value of the
7152 synchronized object would probably need to use a busy-wait loop.]}
7153 @end{Reason}
7154 @end{Itemize}
7155
7156 @ChgRef{Version=[5],Kind=[AddedNormal]}
7157 @ChgAdded{Version=[5],Type=[Leading],Text=[Known_Tasking_Conflict_Checks@\If
7158 this policy applies to two concurrent actions appearing within
7159 @Defn{Known_Tasking_Conflict_Checks conflict check policy}the same compilation
7160 unit, at least one of which appears within a task body but not within a parallel
7161 construct, they are disallowed if they are known to denote the same object (see
7162 @RefSecNum{Parameter Associations}) with uses that conflict, and neither
7163 potentially signals the other (see @RefSecNum{Shared Variables}). For the
7164 purposes of this check, any named task type may be presumed to have multiple
7165 instances. Also, for the purposes of deciding whether two actions are
7166 concurrent, it is enough for the tasks in which they occur to be concurrent at
7167 any point in their execution, unless all of the following are true:]}
7168
7169 @begin{Itemize}
7170 @ChgRef{Version=[5],Kind=[AddedNormal]}
7171 @ChgAdded{Version=[5],Text=[the shared object is volatile;]}
7172
7173 @ChgRef{Version=[5],Kind=[AddedNormal]}
7174 @ChgAdded{Version=[5],Text=[the two tasks are both known to also refer to a
7175 shared synchronized object; and]}
7176
7177 @ChgRef{Version=[5],Kind=[AddedNormal]}
7178 @ChgAdded{Version=[5],Text=[each task whose potentially conflicting action
7179 updates the shared volatile object, also updates this shared synchronized
7180 object.]}
7181
7182 @begin{Reason}
7183 @ChgRef{Version=[5],Kind=[AddedNormal]}
7184 @ChgAdded{Version=[5],Text=[To properly synchronize two actions to prevent
7185 concurrency, a task that does an update of a @i{non}volatile object must
7186 use signaling via a synchronized object to indicate it has completed its
7187 update, and the other task needs to be signaled by this action on the
7188 synchronized object before it reads the updated nonvolatile object. In
7189 other words, to synchronize communication via a nonvolatile object,
7190 signaling must be used. To synchronize communication via a volatile
7191 object, an update of a shared synchronized object followed by a read of
7192 the synchronized object in the other task can be sufficient.]}
7193 @end{Reason}
7194 @end{Itemize}
7195
7196 @ChgRef{Version=[5],Kind=[AddedNormal]}
7197 @ChgAdded{Version=[5],Text=[All_Parallel_Conflict_Checks@\This policy includes
7198 the restrictions imposed by the Known_Parallel_Conflict_Checks policy, and in
7199 @Defn{All_Parallel_Conflict_Checks conflict check policy}addition
7200 disallows a parallel construct from reading or updating a variable that
7201 is global to the construct, unless it is a synchronized object, or unless the
7202 construct is a parallel loop, and the global variable is a part of a component
7203 of an array denoted by an indexed component with at least one index expression
7204 that statically denotes the loop parameter of the
7205 @nt{loop_parameter_specification} or the chunk parameter of the parallel loop.]}
7206
7207 @ChgRef{Version=[5],Kind=[AddedNormal]}
7208 @ChgAdded{Version=[5],Text=[All_Tasking_Conflict_Checks@\This policy includes
7209 @Defn{All_Tasking_Conflict_Checks conflict check policy}the restrictions
7210 imposed by the Known_Tasking_Conflict_Checks policy, and in
7211 addition disallows a task body from reading or updating a variable that is
7212 global to the task body, unless it is a synchronized object.]}
7213
7214 @ChgRef{Version=[5],Kind=[AddedNormal]}
7215 @ChgAdded{Version=[5],Text=[No_Conflict_Checks, Known_Conflict_Checks,
7216 All_Conflict_Checks@\These are short hands for (No_Parallel_Conflict_Checks,
7217 @Defn{No_Conflict_Checks conflict check policy}No_Tasking_Conflict_Checks),
7218 (Known_Parallel_Conflict_Checks,
7219 @Defn{Known_Conflict_Checks conflict check policy}Known_Tasking_Conflict_Checks),
7220 and (All_Parallel_Conflict_Checks,
7221 @Defn{All_Conflict_Checks conflict check policy}All_Tasking_Conflict_Checks),
7222 respectively.]}
7223
7224 @end{Description}
7225
7226 @end{Legality}
7227
7228 @begin{ImplPerm}
7229
7230 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1],ARef=[AI12-0298-1]}
7231 @ChgAdded{Version=[5],Text=[When the conflict check policy
7232 Known_Parallel_Conflict_Checks applies, the implementation may disallow two
7233 concurrent actions appearing within parallel constructs if the implementation
7234 can prove they will at run-time denote the same object with uses that conflict.
7235 Similarly, when the conflict check policy Known_Tasking_Conflict_Checks applies,
7236 the implementation may disallow two concurrent actions, at least one of which
7237 appears within a task body but not within a parallel construct, if the
7238 implementation can prove they will at run-time denote the same object with uses
7239 that conflict.]}
7240
7241 @begin{Ramification}
7242 @ChgRef{Version=[5],Kind=[AddedNormal]}
7243 @ChgAdded{Version=[5],Text=[This permission allows additional enforcement in
7244 instance bodies (where @LegalityTitle aren't usually enforced), in subunits
7245 and their parents, and across compilation units, if the implementation
7246 wishes.]}
7247 @end{Ramification}
7248 @end{ImplPerm}
7249
7250 @begin{Extend2012}
7251 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0267-1]}
7252 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
7253 Conflict check policies (and the associated checks) are new.]}
7254 @end{Extend2012}
7255
7256
7257 @LabeledClause{Example of Tasking and Synchronization}
7258
7259 @begin{Examples}
7260
7261 @Leading@;The following example defines a buffer protected object
7262 to smooth variations between
7263 the speed of output of a producing task and the speed of input of some
7264 consuming task. For instance, the producing task might have the
7265 following structure:
7266
7267 @begin(Example)
7268 @key(task) Producer;
7269
7270 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
7271 @key(task body) Producer @key(is)
7272 @Chg{Version=[2],New=[Person : Person_Name; --@RI[ see @RefSecNum{Incomplete Type Declarations}]],Old=[Char : Character;]}
7273 @key(begin)
7274 @key(loop)
7275 ... --@RI[ @Chg{Version=[2],New=[simulate arrival of the next customer],Old=[produce the next character Char]}]
7276 Buffer.@Chg{Version=[2],New=[Append_Wait(Person)],Old=[Write(Char)]};
7277 @key(exit) @key(when) @Chg{Version=[2],New=[Person = @key(null)],Old=[Char = ASCII.EOT]};
7278 @key(end) @key(loop);
7279 @key(end) Producer;
7280 @end(Example)
7281
7282 @leading@keepnext@;and the consuming task might have the following structure:
7283
7284 @begin(Example)
7285 @key(task) Consumer;
7286
7287 @Trailing@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}@key(task body) Consumer @key(is)
7288 @Chg{Version=[2],New=[Person : Person_Name;],Old=[Char : Character;]}
7289 @key(begin)
7290 @key(loop)
7291 Buffer.@Chg{Version=[2],New=[Remove_First_Wait(Person)],Old=[Read(Char)]};
7292 @key(exit) @key(when) @Chg{Version=[2],New=[Person = @key(null)],Old=[Char = ASCII.EOT]};
7293 ... --@RI[ @Chg{Version=[2],New=[simulate serving a customer],Old=[consume the character Char]}]
7294 @key(end) @key(loop);
7295 @key(end) Consumer;
7296 @end(Example)
7297
7298 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
7299 The buffer object contains an internal @Chg{Version=[2],New=[array],Old=[pool]}
7300 of @Chg{Version=[2],New=[person names],Old=[characters]} managed in a
7301 round-robin fashion. The @Chg{Version=[2],New=[array],Old=[pool]} has two
7302 indices, an In_Index denoting the @Chg{Version=[2],New=[index],Old=[space]}
7303 for the next input @Chg{Version=[2],New=[person name],Old=[character]} and an
7304 Out_Index denoting the @Chg{Version=[2],New=[index],Old=[space]} for the next
7305 output @Chg{Version=[2],New=[person name],Old=[character]}.
7306
7307 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00433-01]}
7308 @ChgAdded{Version=[2],Text=[The Buffer is defined as an extension of the
7309 Synchronized_Queue interface (see @RefSecNum{Interface Types}), and as such
7310 promises to implement the abstraction defined by that interface. By doing so,
7311 the Buffer can be passed to the Transfer class-wide operation defined for
7312 objects of a type covered by Queue'Class.]}
7313
7314 @begin(Example)
7315 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0178-1]}
7316 @ChgAdded{Version=[5],Text=[@key(type) Person_Name_Array @key(is array) (Positive @b<range> <>) @key(of) Person_Name; --@RI[ see @RefSecNum{Incomplete Type Declarations}]]}
7317
7318 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
7319 @key(protected) Buffer @key(is)@Chg{Version=[2],New=[ @key(new) Synchronized_Queue @key(with) --@RI[ see @RefSecNum{Interface Types}]],Old=[]}
7320 @key(entry) @Chg{Version=[2],New=[Append_Wait(Person : @key(in) Person_Name);],Old=[Read (C : @key(out) Character);]}
7321 @key(entry) @Chg{Version=[2],New=[Remove_First_Wait(Person : @key(out) Person_Name);
7322 @key(function) Cur_Count @key(return) Natural;
7323 @key(function) Max_Count @key(return) Natural;
7324 @key(procedure) Append(Person : @key(in) Person_Name);
7325 @key(procedure) Remove_First(Person : @key(out) Person_Name);],Old=[Write(C : @key(in) Character);]}
7326 @key(private)
7327 Pool : @Chg{Version=[2],New=[Person_Name_Array],Old=[String]}(1 .. 100);
7328 Count : Natural := 0;
7329 In_Index, Out_Index : Positive := 1;
7330 @key(end) Buffer;
7331
7332 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
7333 @key(protected body) Buffer @key(is)
7334 @key(entry) @Chg{Version=[2],New=[Append_Wait(Person : @key(in) Person_Name)],Old=[Write(C : @key(in) Character)]}
7335 @key(when) Count < Pool'Length @key(is)
7336 @key(begin)
7337 @Chg{Version=[2],New=[Append(Person);],Old=[Pool(In_Index) := C;
7338 In_Index := (In_Index @key(mod) Pool'Length) + 1;
7339 Count := Count + 1;]}
7340 @key(end) @Chg{Version=[2],New=[Append_Wait],Old=[Write]};
7341
7342 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00433-01]}
7343 @ChgAdded{Version=[2],Text=[ @key(procedure) Append(Person : @key(in) Person_Name) @key(is)
7344 @key(begin)
7345 @key(if) Count = Pool'Length @key(then)
7346 @key(raise) Queue_Error @key(with) "Buffer Full"; --@RI[ see @RefSecNum{Raise Statements and Raise Expressions}]
7347 @key(end if);
7348 Pool(In_Index) := Person;
7349 In_Index := (In_Index @key(mod) Pool'Length) + 1;
7350 Count := Count + 1;
7351 @key(end) Append;]}
7352
7353 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
7354 @key(entry) @Chg{Version=[2],New=[Remove_First_Wait(Person : @key(out) Person_Name)],Old=[Read(C : @key(out) Character)]}
7355 @key(when) Count > 0 @key(is)
7356 @key(begin)
7357 @Chg{Version=[2],New=[Remove_First(Person);],Old=[C := Pool(Out_Index);
7358 Out_Index := (Out_Index @key(mod) Pool'Length) + 1;
7359 Count := Count - 1;]}
7360 @key(end) @Chg{Version=[2],New=[Remove_First_Wait],Old=[Read;
7361 @key(end) Buffer]};
7362
7363 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
7364 @ChgAdded{Version=[2],Text=[ @key(procedure) Remove_First(Person : @key(out) Person_Name) @key(is)
7365 @key(begin)
7366 @key(if) Count = 0 @key(then)
7367 @key(raise) Queue_Error @key(with) "Buffer Empty"; --@RI[ see @RefSecNum{Raise Statements and Raise Expressions}]
7368 @key(end if);
7369 Person := Pool(Out_Index);
7370 Out_Index := (Out_Index @key(mod) Pool'Length) + 1;
7371 Count := Count - 1;
7372 @key(end) Remove_First;]}
7373
7374 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
7375 @ChgAdded{Version=[2],Text=[ @key(function) Cur_Count @key(return) Natural @key(is)
7376 @key(begin)
7377 @key(return) Buffer.Count;
7378 @key(end) Cur_Count;]}
7379
7380 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
7381 @ChgAdded{Version=[2],Text=[ @key(function) Max_Count @key(return) Natural @key(is)
7382 @key(begin)
7383 @key(return) Pool'Length;
7384 @key(end) Max_Count;
7385 @key(end) Buffer;]}
7386 @end(Example)
7387
7388 @end{Examples}
7389