Debian Codegraph @

source_2012/09.mss

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