Debian Codegraph @

source_2005/09.mss

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