Debian Codegraph @

source_2020/sp.mss

raw
1 @comment{ $Source: e:\\cvsroot/ARM/Source/sp.mss,v $ }
2 @comment{ $Revision: 1.91 $ $Date: 2020/06/03 00:09:01 $ $Author: randy $ }
3 @Part(sysprog, Root="ada.mss")
4 @Comment{$Date: 2020/06/03 00:09:01 $}
5
6 @LabeledNormativeAnnex{Systems Programming}
7
8 @begin{Intro}
9 @Redundant[@Defn{systems programming}
10 @Defn{low-level programming}
11 @Defn{real-time systems}
12 @Defn{embedded systems}
13 @Defn{distributed systems}
14 @Defn{information systems}
15 The Systems Programming Annex specifies additional capabilities
16 provided for low-level programming. These capabilities are also
17 required in many real-time, embedded, distributed, and information systems.]
18 @end{Intro}
19
20 @begin{Extend83}
21 @Defn{extensions to Ada 83}
22 This Annex is new to Ada 95.
23 @end{Extend83}
24
25 @LabeledClause{Access to Machine Operations}
26
27 @begin{Intro}
28 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
29 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies rules regarding access to machine instructions
30 from within an Ada program.]
31 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
32 Text=[@Chg{Version=[2],
33 New=[Implementation-defined intrinsic subprograms],
34 Old=[Support for access to machine instructions]}.]}
35 @end{Intro}
36
37 @begin{ImplReq}
38 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0320-1]}
39 @Defn{machine code insertion}
40 The implementation shall support machine code insertions
41 (see @RefSecNum{Machine Code Insertions}) or intrinsic subprograms
42 (see @RefSecNum{Conformance Rules}) (or both).
43 @Chg{Version=[5],New=[The implementation],Old=[Implementation-defined
44 attributes]} shall @Chg{Version=[5],New=[],Old=[be provided to ]}allow
45 the use of Ada entities as operands@Chg{Version=[5],New=[ for such
46 machine code insertions or intrinsic subprograms],Old=[]}.
47
48 @begin{Discussion}
49 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0320-1]}
50 @ChgAdded{Version=[5],Text=[Ada entities could be used as operands in machine
51 code insertions and/or intrinsic subprograms using language-defined attributes
52 (such as address), implementation-defined attributes, or could be directly
53 allowed.]}
54 @end{Discussion}
55 @end{ImplReq}
56
57 @begin{ImplAdvice}
58 The machine code or intrinsics support should allow access to all
59 operations normally available to assembly language programmers for the
60 target environment,
61 including privileged instructions, if any.
62 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
63 Text=[The machine code or intrinsics support should allow access to all
64 operations normally available to assembly language programmers for the
65 target environment.]}]}
66 @begin{Ramification}
67 Of course, on a machine with protection, an attempt to execute a
68 privileged instruction in user mode will probably trap.
69 Nonetheless, we want implementations to provide access to them so that
70 Ada can be used to write systems programs that run in privileged mode.
71 @end{Ramification}
72
73 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
74 @Defn{interface to assembly language}
75 @Defn2{Term=[language], Sec=(interface to assembly)}
76 @Defn{mixed-language programs}
77 @Defn{assembly language}
78 The @Chg{Version=[3],New=[support for ],Old=[]}interfacing @Chg{Version=[3],New=[aspects],Old=[pragmas]}
79 (see @RefSecNum{Interface to Other Languages})
80 should @Chg{Version=[3],New=[include],Old=[support]} interface to assembler;
81 the default assembler should be associated with the convention
82 identifier Assembler.
83 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
84 Text=[Interface to assembler should be supported; the default assembler
85 should be associated with the convention identifier Assembler.]}]}
86
87 If an entity is exported to assembly language, then the implementation
88 should allocate it at an addressable location,
89 and should ensure that it is retained by the linking process,
90 even if not otherwise referenced from the Ada code.
91 The implementation should assume that any call to a machine code or
92 assembler subprogram is allowed to read or update every object that is
93 specified as exported.
94 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
95 Text=[If an entity is exported to assembly language, then the implementation
96 should allocate it at an addressable location even if not otherwise referenced
97 from the Ada code. A call to a machine code or assembler subprogram should
98 be treated as if it could read or update every object that is
99 specified as exported.]}]}
100 @end{ImplAdvice}
101
102 @begin{DocReq}
103
104 The implementation shall document the overhead associated with calling
105 machine-code or intrinsic subprograms, as compared to a fully-inlined
106 call, and to a regular out-of-line call.
107 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
108 Text=[The overhead of calling machine-code or intrinsic subprograms.]}]}
109
110 The implementation shall document the types of
111 the package System.Machine_Code usable for machine code
112 insertions, and the attributes to be used in
113 machine code insertions for references to Ada entities.
114 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
115 Text=[The types and attributes used in machine code insertions.]}]}
116
117 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
118 The implementation shall document the subprogram calling conventions
119 associated with the convention identifiers available for use
120 with the @Chg{Version=[3],New=[Convention aspect],Old=[interfacing pragmas]}
121 (Ada and Assembler, at a minimum),
122 including register saving,
123 exception propagation, parameter passing, and function value returning.
124 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
125 Text=[The subprogram calling conventions for all supported convention
126 identifiers.]}]}
127
128 For exported and imported subprograms,
129 the implementation shall document the mapping
130 between the Link_Name string, if specified, or
131 the Ada designator, if not, and the external link name used
132 for such a subprogram.
133 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
134 Text=[@ChgDeleted{Version=[2],
135 Text=[Implementation-defined aspects of access to machine operations.]}]}
136 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
137 Text=[The mapping between the Link_Name or Ada designator and the external
138 link name.]}]}
139
140 @end{DocReq}
141
142 @begin{ImplAdvice}
143
144 The implementation should ensure that little or no overhead is associated
145 with calling intrinsic and machine-code subprograms.
146 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
147 Text=[Little or no overhead should be associated
148 with calling intrinsic and machine-code subprograms.]}]}
149
150 @Leading@;It is recommended that intrinsic subprograms be provided for convenient
151 access to any machine operations that provide special capabilities
152 or efficiency and that are not otherwise available through the language
153 constructs. Examples of such instructions
154 include:
155 @begin{itemize}
156
157 Atomic read-modify-write operations @em e.g., test and set, compare and swap,
158 decrement and test, enqueue/dequeue.
159
160 Standard numeric functions @em e.g., @i{sin}, @i{log}.
161
162 String manipulation operations @em e.g., translate and test.
163
164 Vector operations @em e.g., compare vector against thresholds.
165
166 Direct operations on I/O ports.
167
168 @end{itemize}
169 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
170 Text=[Intrinsic subprograms should be provided to access any machine operations
171 that provide special capabilities or efficiency not normally available.]}]}
172
173 @end{ImplAdvice}
174
175 @LabeledClause{Required Representation Support}
176
177 @begin{Intro}
178 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
179 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
180 This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies minimal requirements on the
181 @Chg{Version=[2],New=[],Old=[implementation's ]}support for representation
182 items and related features.
183 @end{Intro}
184
185 @begin{ImplReq}
186 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
187 @PDefn2{Term=[recommended level of support], Sec=(required in Systems
188 Programming Annex)}
189 The implementation shall support at least the functionality
190 defined by the recommended levels of support in @Chg{Version=[3],New=[Clause],
191 Old=[Section]} @RefSecNum{Representation Issues}.
192 @end{ImplReq}
193
194 @LabeledClause{Interrupt Support}
195
196 @begin{Intro}
197 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
198 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies
199 the language-defined model for hardware interrupts
200 in addition to mechanisms for handling interrupts.]
201 @IndexSee{Term=[signal],See=(interrupt)}
202 @end{Intro}
203
204 @begin{RunTime}
205
206 @Defn{interrupt}
207 @Redundant[An @i{interrupt} represents a class of events that are detected by
208 the hardware or the system software.]
209 @Defn2{Term=[occurrence], Sec=(of an interrupt)}
210 Interrupts are said to occur. An @i{occurrence} of an interrupt is
211 separable into generation and delivery.
212 @Defn2{Term=[generation], Sec=(of an interrupt)}
213 @i{Generation} of an interrupt is the event in the underlying hardware
214 or system that makes the interrupt available to the program.
215 @Defn2{Term=[delivery], Sec=(of an interrupt)}
216 @i{Delivery} is the action that invokes part of the program as
217 response to the interrupt occurrence.
218 @Defn{pending interrupt occurrence}
219 Between generation and delivery, the interrupt occurrence @Redundant[(or
220 interrupt)] is @i{pending}.
221 @Defn{blocked interrupt}
222 Some or all interrupts may be @i{blocked}. When an interrupt is blocked, all
223 occurrences of that interrupt are prevented from being delivered.
224 @Defn2{Term=[attaching], Sec=(to an interrupt)}
225 @Defn{reserved interrupt}
226 Certain interrupts are @i{reserved}. The set of reserved interrupts is
227 implementation defined. A reserved interrupt is either an interrupt for
228 which user-defined handlers are not supported, or one which
229 already has an attached handler by some other implementation-defined means.
230 @Defn{interrupt handler}@PDefn2{Term=[handler],Sec=[interrupt]}
231 Program units can be connected to nonreserved interrupts. While
232 connected, the program unit is said to be @i{attached} to that interrupt.
233 The execution of that program unit, the @i{interrupt handler}, is invoked upon
234 delivery of the interrupt occurrence.
235 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
236 Text=[@ChgDeleted{Version=[2],
237 Text=[Implementation-defined aspects of interrupts.]}]}
238 @begin{Honest}
239 As an obsolescent feature,
240 interrupts may be attached to task entries by an address clause.
241 See @RefSecNum{Interrupt Entries}.
242 @end{Honest}
243
244 While a handler is attached to an interrupt, it is called once for each
245 delivered occurrence of that interrupt. While the handler executes, the
246 corresponding interrupt is blocked.
247
248 While an interrupt is blocked, all occurrences of that interrupt are prevented
249 from being delivered. Whether such occurrences remain pending or are lost is
250 implementation defined.
251
252 @Defn{default treatment}
253 Each interrupt has a @i{default treatment} which determines the system's
254 response to an occurrence of that interrupt when no user-defined
255 handler is attached. The set of possible default treatments is
256 implementation defined, as is the method (if one exists) for configuring
257 the default treatments for interrupts.
258
259 An interrupt is delivered to the handler (or default treatment) that is in
260 effect for that interrupt at the time of delivery.
261
262 An exception propagated from a handler that is invoked by an
263 interrupt has no effect.
264
265 @Redundant[If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
266 in effect, the interrupt handler executes with the active priority that is the
267 ceiling priority of the corresponding protected object.]
268
269 @end{RunTime}
270
271 @begin{ImplReq}
272
273 The implementation shall provide a mechanism to determine the minimum
274 stack space that is needed
275 for each interrupt handler and to reserve that space for
276 the execution of the handler. @Redundant{This space should accommodate
277 nested invocations of the handler where the system permits this.}
278
279 If the hardware or the underlying system holds pending interrupt
280 occurrences, the implementation shall provide for later delivery
281 of these occurrences to the program.
282
283 If the Ceiling_Locking policy is not in effect, the implementation
284 shall provide means for the application to specify whether interrupts
285 are to be blocked during protected actions.
286
287 @end{ImplReq}
288
289 @begin{DocReq}
290 @Leading@;The implementation shall document the following items:
291 @begin{Discussion}
292 This information may be different for different forms of interrupt handlers.
293 @end{Discussion}
294 @begin{Enumerate}
295 For each interrupt, which interrupts are blocked from delivery when a handler
296 attached to that interrupt executes (either as a result of an interrupt
297 delivery or of an ordinary call on a procedure of the corresponding
298 protected object).
299
300 Any interrupts that cannot be blocked, and the effect of attaching
301 handlers to such interrupts, if this is permitted.
302
303 Which run-time stack an interrupt handler uses when it executes as a
304 result of an interrupt delivery; if this is configurable, what is the
305 mechanism to do so; how to specify how much space to reserve on that stack.
306
307 Any implementation- or hardware-specific activity that happens
308 before a user-defined interrupt handler gets control (e.g.,
309 reading device registers, acknowledging devices).
310
311 Any timing or other limitations imposed on the execution of interrupt handlers.
312
313 The state (blocked/unblocked) of the nonreserved interrupts
314 when the program starts; if some interrupts are unblocked, what
315 is the mechanism a program can use to protect itself before it
316 can attach the corresponding handlers.
317
318 Whether the interrupted task is allowed to resume execution before the
319 interrupt handler returns.
320
321 The treatment of interrupt occurrences that are generated while
322 the interrupt is blocked; i.e., whether one or more occurrences
323 are held for later delivery, or all are lost.
324
325 Whether predefined or implementation-defined exceptions are raised as a
326 result of the occurrence of any interrupt, and the mapping between the
327 machine interrupts (or traps) and the predefined
328 exceptions.
329
330 On a multi-processor, the rules governing the delivery of an interrupt
331 to a particular processor.
332 @end{Enumerate}
333 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
334 Text=[The treatment of interrupts.]}]}
335 @ChgNote{A Bob Duff explanation, but this is just too much junk.}
336 @end{DocReq}
337
338 @begin{ImplPerm}
339
340 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
341 If the underlying system or hardware does not allow interrupts to be
342 blocked, then no blocking is required @Redundant[as part of the execution of
343 subprograms of a protected object @Chg{Version=[2],New=[for which],Old=[whose]}
344 one of its subprograms is an interrupt handler].
345
346 In a multi-processor with more than one interrupt subsystem, it is
347 implementation defined whether (and how) interrupt sources from
348 separate subsystems share the same Interrupt_Id type
349 (see @RefSecNum{The Package Interrupts}).
350 In particular, the meaning of a blocked or pending interrupt may then be
351 applicable to one processor only.
352 @begin{discussion}
353 This issue is tightly related to the issue of scheduling on a
354 multi-processor. In a sense, if a particular interrupt source is not
355 available to all processors, the system is not truly homogeneous.
356
357 One way to approach this problem is to assign sub-ranges within
358 Interrupt_Id to each interrupt subsystem, such that @lquotes@;similar@rquotes@; interrupt
359 sources (e.g. a timer) in different subsystems get a distinct id.
360 @end{Discussion}
361
362 Implementations are allowed to impose timing or other limitations on the
363 execution of interrupt handlers.
364 @begin{Reason}
365 These limitations are often necessary to ensure proper behavior of the
366 implementation.
367 @end{Reason}
368
369 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
370 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
371 Other forms of handlers are allowed to be supported, in which
372 case@Chg{Version=[2],New=[],Old=[,]} the rules of this
373 @Chg{Version=[3],New=[subclause],Old=[@Chg{Version=[2],New=[clause],Old=[subclause]}]}
374 should be adhered to.
375
376 The active priority of the execution of an interrupt handler is allowed to
377 vary from one occurrence of the same interrupt to another.
378
379 @end{ImplPerm}
380
381 @begin{ImplAdvice}
382
383 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
384 If the Ceiling_Locking policy is not in effect, the implementation
385 should provide means for the application to specify which interrupts
386 are to be blocked during protected actions, if the underlying system allows
387 for @Chg{Version=[2],New=[finer-grained],Old=[a finer-grain]} control of
388 interrupt blocking.
389 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
390 Text=[If the Ceiling_Locking policy is not in effect and the target system
391 allows for finer-grained control of interrupt blocking, a means for the
392 application to specify which interrupts are to be blocked during protected
393 actions should be provided.]}]}
394
395 @end{ImplAdvice}
396
397 @begin{Notes}
398
399 The default treatment for an interrupt can be to keep the
400 interrupt pending or to deliver it to an implementation-defined
401 handler. Examples of actions that an implementation-defined
402 handler is allowed to perform include aborting the partition, ignoring
403 (i.e., discarding occurrences of) the interrupt, or queuing one
404 or more occurrences of the interrupt for possible later delivery
405 when a user-defined handler is attached to that interrupt.
406
407 It is a bounded error to call Task_Identification.Current_Task
408 (see @RefSecNum{The Package Task_Identification}) from an interrupt handler.
409
410 The rule that an exception propagated from an interrupt handler has no effect
411 is modeled after the rule about exceptions propagated out of task bodies.
412
413 @end{Notes}
414
415 @LabeledSubClause{Protected Procedure Handlers}
416
417 @begin{NotIso}
418 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 1
419 through 6 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
420 should be deleted if the paragraphs are ever renumbered.}
421 @end{NotIso}
422
423 @begin{Syntax}
424 @begin{SyntaxText}
425 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
426 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
427 @nt{pragma} Interrupt_Handler is as follows:]}
428 @end{SyntaxText}
429
430 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
431 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
432 Text=[@key{pragma} @prag(Interrupt_Handler)(@SynI{handler_}@Syn2{name});]}>
433
434 @begin{SyntaxText}
435 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
436 @ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[The form of a
437 @nt{pragma} Attach_Handler is as follows:]}
438 @end{SyntaxText}
439
440 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
441 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
442 Text=[@key{pragma} @prag(Attach_Handler)(@SynI{handler_}@Syn2{name}, @Syn2{expression});]}>
443 @end{Syntax}
444
445 @begin{Resolution}
446 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
447 @ChgDeleted{Version=[3],Text=[For the Interrupt_Handler and Attach_Handler
448 pragmas, the @SynI{handler_}@nt{name} shall resolve to denote a protected
449 procedure with a parameterless profile.]}
450
451 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
452 @ChgDeleted{Version=[3],Text=[For the Attach_Handler pragma, the expected type
453 for the @nt{expression} is Interrupts.Interrupt_Id
454 (see @RefSecNum{The Package Interrupts}).]}
455 @end{Resolution}
456
457 @begin{StaticSem}
458 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
459 @ChgAdded{Version=[3],Type=[Leading],Text=[For a parameterless protected
460 procedure, the following language-defined representation aspects may be
461 specified:]}
462 @begin{Description}
463 @ChgRef{Version=[3],Kind=[Added]}
464 @ChgAdded{Version=[3],Text=[Interrupt_Handler@\
465 The type of aspect Interrupt_Handler is Boolean.
466 If directly specified, the aspect_definition shall be a static expression.
467 @Redundant[This aspect is never inherited;] if not directly specified,
468 the aspect is False.@AspectDefn{Interrupt_Handler}]}
469
470 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Interrupt_Handler],
471 Text=[@ChgAdded{Version=[3],Text=[Protected procedure may be attached to
472 interrupts.]}]}
473
474 @ChgRef{Version=[3],Kind=[Added]}
475 @ChgAdded{Version=[3],Text=[Attach_Handler@\
476 The aspect Attach_Handler is an @nt{expression}, which shall be of type
477 Interrupts.Interrupt_Id. @Redundant[This aspect is never
478 inherited.]@AspectDefn{Attach_Handler}]}
479
480 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Attach_Handler],
481 Text=[@ChgAdded{Version=[3],Text=[Protected procedure is attached to an
482 interrupt.]}]}
483
484 @end{Description}
485
486 @end{StaticSem}
487
488 @begin{Legality}
489
490 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
491 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0033-1],ARef=[AI05-0229-1]}
492 @Chg{Version=[3],New=[If either the],Old=[The]} Attach_Handler
493 @Chg{Version=[3],New=[or Interrupt_Handler aspect are specified for a
494 protected procedure, the],Old=[pragma is only allowed immediately within the
495 @nt{protected_definition} where the corresponding subprogram is declared.
496 The]} corresponding @nt{protected_@!type_@!declaration}
497 or @nt{single_@!protected_@!declaration}
498 shall be a library@Chg{Version=[2],New=[-],Old=[]}level
499 declaration@Chg{Version=[3],New=[ and shall not be declared within a
500 generic body. @PDefn{generic contract issue}In addition
501 to the places where @LegalityTitle normally apply
502 (see @RefSecNum{Generic Instantiation}), this rule also applies
503 in the private part of an instance of a generic unit],Old=[]}.
504
505 @begin{Discussion}
506 In the case of a @nt{protected_type_declaration},
507 an @nt{object_declaration} of an object of that type
508 need not be at library level.
509
510 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1],ARef=[AI05-0229-1]}
511 @ChgAdded{Version=[3],Text=[We cannot allow these aspects in protected
512 declarations in a generic body, because legality rules are not checked for
513 instance bodies, and these should not be allowed if the instance is not at the
514 library level. The protected types can be declared in the private part if this
515 is desired. Note that while the 'Access to use the handler would provide the
516 check in the case of Interrupt_Handler, there is no other check for
517 Attach_Handler. Since these aspects are so similar, we want the rules to be the
518 same.]}
519 @end{Discussion}
520
521 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00253-01],ARef=[AI95-00303-01]}
522 @ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0033-1]}
523 @ChgDeleted{Version=[3],Text=[The Interrupt_Handler pragma is only
524 allowed immediately within @Chg{Version=[2],New=[the],Old=[a]}
525 @nt{protected_definition}@Chg{Version=[2],New=[ where the
526 corresponding subprogram is declared],Old=[]}.
527 The cor@!responding @nt{protected_@!type_declaration} @Chg{Version=[2],New=[or
528 @nt{single_@!protected_@!declaration} ],Old=[]}shall
529 be a library@Chg{Version=[2],New=[-],Old=[]}level
530 declaration.@Chg{Version=[2],New=[],Old=[ In addition, any
531 @nt{object_@!declaration} of such a type shall be a library level declaration.]}]}
532 @end{Legality}
533
534 @begin{RunTime}
535
536 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
537 If the @Chg{Version=[3],New=[],Old=[pragma ]}Interrupt_Handler
538 @Chg{Version=[3],New=[aspect of a protected procedure is True],Old=[appears in a
539 @nt{protected_definition}]}, then the
540 @Chg{Version=[3],New=[],Old=[corresponding ]}procedure
541 @Chg{Version=[3],New=[may],Old=[can]}
542 be attached dynamically, as a handler, to
543 interrupts (see @RefSecNum{The Package Interrupts}).
544 @Redundant[Such procedures are allowed to be attached to multiple interrupts.]
545
546 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
547 @Defn2{Term=[creation], Sec=(of a protected object)}
548 @Defn2{Term=[initialization], Sec=(of a protected object)}
549 The @nt{expression} @Chg{Version=[3],New=[specified for],Old=[in]} the
550 Attach_Handler @Chg{Version=[3],New=[aspect of a protected procedure @i<P>
551 is evaluated as part of the creation of the protected object that
552 contains @i<P>.
553 The value of the @nt{expression} identifies],Old=[pragma @Redundant[as evaluated at
554 object creation time] specifies]} an interrupt. As part
555 of the initialization of that object,
556 @Chg{Version=[3],New=[@i<P> (],Old=[if the Attach_Handler pragma is
557 specified, ]}the @SynI{handler}
558 procedure@Chg{Version=[3],New=[)],Old=[]}
559 is attached to the @Chg{Version=[3],New=[identified],Old=[specified]} interrupt.
560 @IndexCheck{Reserved_Check}
561 A check is made that the corresponding interrupt is not reserved.
562 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
563 Program_Error is raised if the check fails, and the existing treatment
564 for the interrupt is not affected.
565
566 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
567 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
568 @Defn2{Term=[initialization], Sec=(of a protected object)}
569 @IndexCheck{Ceiling_Check}
570 If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
571 in effect@Chg{Version=[2],New=[,],Old=[]} then upon the initialization of a
572 protected object @Chg{Version=[3],New=[that contains a protected
573 procedure ],Old=[]}@Chg{Version=[2],New=[for which],Old=[that]} either
574 @Chg{Version=[3],New=[the],Old=[an]}
575 Attach_Handler@Chg{Version=[3],New=[ aspect is specified],Old=[]} or
576 @Chg{Version=[3],New=[the ],Old=[]} Interrupt_Handler
577 @Chg{Version=[3],New=[aspect is True],Old=[pragma applies to one of its
578 procedures]},
579 a check is made that the @Chg{Version=[3],New=[initial ],Old=[]}ceiling
580 priority @Chg{Version=[3],New=[of the object],Old=[defined in the
581 @nt{protected_definition}]} is in the range of System.@!Interrupt_Priority.
582 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
583 If the check fails, Program_Error is raised.
584
585 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0068],ARef=[AI95-00121-01]}
586 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
587 @Defn2{Term=[finalization], Sec=(of a protected object)}
588 When a protected object is finalized, for any of its procedures that are
589 attached to interrupts, the handler is detached. If the handler was
590 attached by a procedure in the Interrupts package or if no user
591 handler was previously attached to the interrupt, the default treatment is
592 restored. @Chg{New=[If @Chg{Version=[3],New=[the],Old=[an]} Attach_@!Handler
593 @Chg{Version=[3],New=[aspect],Old=[pragma]} was
594 @Chg{Version=[3],New=[specified],Old=[used]} and the most recently
595 attached handler for the same interrupt is the same as the one that was
596 attached at the time the protected object was initialized],
597 Old=[Otherwise, @Redundant[that is, if an
598 Attach_@!Handler pragma was specified]]}, the previous handler is
599 restored.
600 @begin{Discussion}
601 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0068],ARef=[AI95-00121-01]}
602 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00303-01]}
603 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
604 @Chg{New=[If all protected objects for interrupt handlers are declared at the
605 library@Chg{Version=[2],New=[ ],Old=[-]}level],Old=[Since only library-level
606 protected procedures can be attached as
607 handlers using the Interrupts package]}, the finalization discussed above
608 occurs only as part of the finalization of all library-level packages in
609 a partition.
610 @Chg{New=[However, objects of a protected type containing
611 @Chg{Version=[3],New=[procedures with ],Old=[]}an Attach_@!Handler
612 @Chg{Version=[3],New=[aspect specified],Old=[pragma]} need not be at the library level.
613 Thus, an implementation needs to be
614 able to restore handlers during the execution of the program.@Chg{Version=[2],
615 New=[ (An object with an Interrupt_@!Handler @Chg{Version=[3],New=[aspect],Old=[pragma]}
616 also need not be at the library level, but such
617 a handler cannot be attached to an interrupt using the Interrupts package.)],
618 Old=[]}],Old=[]}
619 @end{Discussion}
620
621 When a handler is attached to an interrupt, the interrupt is blocked
622 @Redundant[(subject to the @ImplPermName in @RefSecNum{Interrupt Support})]
623 during the execution of every protected action on the protected object
624 containing the handler.
625
626 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0252-1]}
627 @ChgAdded{Version=[5],Text=[If restriction No_Dynamic_Attachment is in effect,
628 then a check is made that the interrupt identified by an Attach_Handler aspect
629 does not appear in any previously elaborated Attach_Handler aspect;
630 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
631 Program_Error is raised if this check fails.]}
632
633 @begin{Reason}
634 @ChgRef{Version=[5],Kind=[AddedNormal]}
635 @ChgAdded{Version=[5],Text=[When No_Dynamic_Attachment is in effect,
636 it is not possible to call any previous handler. Therefore, the only
637 possibility is to replace the original handler, rendering it ineffective.
638 Having an unused handler in a program is likely a bug, so we require
639 an exception to be raised.]}
640 @end{Reason}
641 @end{RunTime}
642
643 @begin{Erron}
644 @PDefn2{Term=(erroneous execution),Sec=(cause)}
645 If the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
646 in effect and an interrupt is delivered to a handler, and the interrupt
647 hardware priority is higher than the ceiling priority of the corresponding
648 protected object, the execution of the program is erroneous.
649
650 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0068],ARef=[AI95-00121-01]}
651 @ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0229-1]}
652 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
653 If the handlers for a given interrupt attached via
654 @Chg{Version=[3],New=[aspect],Old=[pragma]} Attach_Handler
655 are not attached and detached in a stack-like (LIFO) order,
656 program execution is erroneous. In particular, when a protected object is
657 finalized, the execution is erroneous if any of the procedures of the
658 protected object are attached to interrupts via
659 @Chg{Version=[3],New=[aspect],Old=[pragma]} Attach_@!Handler and
660 the most recently attached handler for the same interrupt is not the same as
661 the one that was attached at the time the protected object was initialized.]}
662 @begin{Discussion}
663 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0068],ARef=[AI95-00121-01]}
664 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
665 @ChgAdded{Version=[1],Text=[This simplifies implementation of the Attach_@!Handler
666 @Chg{Version=[3],New=[aspect],Old=[pragma]} by not requiring a check that the
667 current handler is the same as the one attached by the initialization of a
668 protected object.]}
669 @end{Discussion}
670 @end{Erron}
671
672 @begin{Metrics}
673 @Leading@Keepnext@;The following metric shall be documented by the implementation:
674 @ChgNote{This was @begin{enumerate}, which is wrong}
675 @begin{Itemize}
676 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
677 The worst@Chg{Version=[2],New=[-],Old=[ ]}case overhead for an interrupt
678 handler that is a parameterless
679 protected procedure, in clock cycles. This is the execution time not
680 directly attributable to the handler procedure or the interrupted execution.
681 It is estimated as C @en@; (A+B), where A is how long it takes to complete a given
682 sequence of instructions without any interrupt, B is how long it takes to
683 complete a normal call to a given protected procedure, and C is how long it
684 takes to complete the same sequence of instructions when it is interrupted by
685 one execution of the same procedure called via an interrupt.
686 @begin{ImplNote}
687 The instruction sequence and interrupt handler used to measure interrupt
688 handling overhead should be chosen so as to maximize the execution time cost
689 due to cache misses. For example, if the processor has cache memory and the
690 activity of an interrupt handler could invalidate the contents of cache memory, the handler should be written such that it invalidates all of the cache memory.
691 @end{ImplNote}
692 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
693 Text=[The metrics for interrupt handlers.]}]}
694 @ChgNote{This was @end{enumerate}, which is wrong}
695 @end{Itemize}
696 @end{Metrics}
697
698 @begin{ImplPerm}
699 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
700 When the @Chg{Version=[3],New=[aspects],Old=[pragmas]} Attach_Handler or
701 Interrupt_Handler @Chg{Version=[3],New=[are specified for],Old=[apply to]}
702 a protected procedure, the implementation is allowed to impose
703 implementation-defined restrictions on the
704 corresponding @nt{protected_@!type_@!declaration} and @nt{protected_@!body}.
705 @begin{Ramification}
706 The restrictions may be on the constructs that are allowed within them,
707 and on ordinary calls (i.e. not via interrupts) on protected operations in
708 these protected objects.
709 @end{Ramification}
710 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[2],
711 Text=[@Chg{Version=[2],
712 New=[Any restrictions on a protected procedure or its containing type when
713 @Chg{Version=[3],New=[an aspect],Old=[a @nt{pragma}]}
714 Attach_handler or Interrupt_Handler
715 @Chg{Version=[3],New=[is specified],Old=[applies]}.],Old=[]}]}
716
717 An implementation may use a different mechanism for invoking a protected
718 procedure in response to a hardware interrupt than is used for a call
719 to that protected procedure from a task.
720 @begin{Discussion}
721 This is despite the fact that the priority of an interrupt handler
722 (see @RefSecNum{Task Priorities}) is modeled after a hardware task calling the
723 handler.
724 @end{Discussion}
725
726 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
727 @Defn{notwithstanding}
728 Notwithstanding what this subclause says elsewhere,
729 the Attach_Handler and Interrupt_Handler
730 @Chg{Version=[3],New=[aspects],Old=[pragmas]} are allowed to be used
731 for other, implementation defined, forms of interrupt handlers.
732 @begin{Ramification}
733 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
734 For example, if an implementation wishes to allow interrupt
735 handlers to have parameters, it is allowed to do so via these
736 @Chg{Version=[3],New=[aspects],Old=[pragmas]};
737 it need not invent implementation-defined
738 @Chg{Version=[3],New=[aspects],Old=[pragmas]} for the purpose.
739 @end{Ramification}
740 @ChgImplDef{Version=[3],Kind=[Revised],InitialVersion=[2],
741 Text=[@Chg{Version=[2],
742 New=[Any other forms of interrupt handler supported by the
743 Attach_Handler and Interrupt_Handler
744 @Chg{Version=[3],New=[aspects],Old=[pragmas]}.],Old=[]}]}
745
746 @end{ImplPerm}
747
748 @begin{ImplAdvice}
749
750 Whenever possible, the implementation should allow interrupt handlers to be
751 called directly by the hardware.
752 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
753 Text=[Interrupt handlers should be called directly by the hardware.]}]}
754
755 Whenever practical, the implementation should
756 detect violations of any implementation-defined restrictions
757 before run time.
758 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
759 Text=[Violations of any implementation-defined restrictions on interrupt
760 handlers should be detected before run time.]}]}
761
762 @end{ImplAdvice}
763
764 @begin{Notes}
765
766 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
767 The Attach_Handler @Chg{Version=[3],New=[aspect may],Old=[pragma can]}
768 provide static attachment of handlers to
769 interrupts if the implementation supports preelaboration of protected
770 objects. (See @RefSecNum{Preelaboration Requirements}.)
771
772 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
773 @Chg{Version=[2],New=[A],Old=[The ceiling priority of a]}
774 protected object that
775 @Chg{Version=[2],New=[has a (protected) procedure],
776 Old=[one of its procedures is]}
777 attached to an interrupt should
778 @Chg{Version=[2],New=[have a ceiling priority],
779 Old=[be]} at least as high as the highest
780 processor priority at which that interrupt will ever be delivered.
781
782 Protected procedures can also be attached dynamically to interrupts
783 via operations declared in the predefined package Interrupts.
784
785 An example of a possible implementation-defined restriction is
786 disallowing the use of the standard storage pools within the body of
787 a protected procedure that is an interrupt handler.
788
789 @end{Notes}
790
791 @begin{Incompatible95}
792 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00253-01]}
793 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
794 @b[Amendment Correction:] Corrected the wording so that the rules for the
795 use of Attach_Handler and Interrupt_Handler are identical. This means
796 that uses of pragma Interrupt_Handler outside of the target protected type
797 or single protected object are now illegal.]}
798 @end{Incompatible95}
799
800 @begin{DiffWord95}
801 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0068],ARef=[AI95-00121-01]}
802 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified the meaning of
803 @lquotes@;the previous handler@rquotes when finalizing protected objects
804 containing interrupt handlers.]}
805
806 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00303-01]}
807 @ChgAdded{Version=[2],Text=[Dropped the requirement that an object of a
808 type containing an Interrupt_Handler pragma must be declared at the library
809 level. This was a generic contract model violation. This change is not
810 an extension, as an attempt to attach such a handler with a routine in
811 package Interrupts will fail an accessibility check anyway. Moreover,
812 implementations can retain the rule as an implementation-defined
813 restriction on the use of the type, as permitted by the @ImplPermTitle
814 above.]}
815 @end{Diffword95}
816
817 @begin{Extend2005}
818 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
819 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
820 Aspects Interrupt_Handler and Attach_Handler are new; @nt{pragma}s
821 Interrupt_Handler and Attach_Handler are now obsolescent.]}
822 @end{Extend2005}
823
824 @begin{DiffWord2005}
825 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0033-1]}
826 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
827 Added missing generic contract wording for the aspects Attach_Handler and
828 Interrupt_Handler.]}
829 @end{DiffWord2005}
830
831 @begin{Inconsistent2012}
832 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0252-1]}
833 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012}
834 @b[Correction:] Program_Error might be raised if two handlers are attached
835 when restriction No_Dynamic_Attachment is in effect (including as part of
836 the Ravenscar profile). Original Ada 2012 would have just ignored the first
837 handler. This is almost certainly a bug rather than an intended result.]}
838 @end{Inconsistent2012}
839
840
841 @LabeledSubClause{The Package Interrupts}
842
843 @begin{StaticSem}
844
845 @Leading@Keepnext@;The following language-defined packages exist:
846 @begin{example}
847 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0167-1]}
848 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
849 @key{with} System;@ChildUnit{Parent=[Ada],Child=[Interrupts]}@Chg{Version=[3],New=[
850 @key{with} System.Multiprocessors;],Old=[]}
851 @key[package] Ada.Interrupts@Chg{Version=[5],New=[
852 @key[with] Nonblocking ],Old=[]}@key[is]
853 @key[type] @AdaTypeDefn{Interrupt_Id} @key[is] @RI{implementation-defined};
854 @key[type] @AdaTypeDefn{Parameterless_Handler} @key[is]
855 @key[access] @key[protected] @key[procedure]@Chg{Version=[5],New=[
856 @key[with] Nonblocking => False],Old=[]};
857
858 @ChgRef{Version=[1], Kind=[Deleted]}
859 @Chg[New=<>,Old=<@ @;@comment{Empty paragraph to hang junk paragraph number from original RM}>]
860
861 @key[function] @AdaSubDefn{Is_Reserved} (Interrupt : Interrupt_Id)
862 @key[return] Boolean;
863
864 @key[function] @AdaSubDefn{Is_Attached} (Interrupt : Interrupt_Id)
865 @key[return] Boolean;
866
867 @key[function] @AdaSubDefn{Current_Handler} (Interrupt : Interrupt_Id)
868 @key[return] Parameterless_Handler;
869
870 @key[procedure] @AdaSubDefn{Attach_Handler}
871 (New_Handler : @key[in] Parameterless_Handler;
872 Interrupt : @key[in] Interrupt_Id);
873
874 @key[procedure] @AdaSubDefn{Exchange_Handler}
875 (Old_Handler : @key[out] Parameterless_Handler;
876 New_Handler : @key[in] Parameterless_Handler;
877 Interrupt : @key[in] Interrupt_Id);
878
879 @key[procedure] @AdaSubDefn{Detach_Handler}
880 (Interrupt : @key[in] Interrupt_Id);
881
882 @key[function] @AdaSubDefn{Reference} (Interrupt : Interrupt_Id)
883 @key{return} System.Address;
884
885 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0167-1]}
886 @ChgAdded{Version=[3],Text=[ @key[function] @AdaSubDefn{Get_CPU} (Interrupt : Interrupt_Id)
887 @key{return} System.Multiprocessors.CPU_Range;]}
888
889 @key[private]
890 ... -- @RI{not specified by the language}
891 @key[end] Ada.Interrupts;
892
893
894 @key[package] Ada.Interrupts.Names @key[is]@ChildUnit{Parent=[Ada.Interrupts],Child=[Names]}
895 @RI{implementation-defined} : @key[constant] Interrupt_Id :=
896 @RI{implementation-defined};
897 . . .
898 @RI{implementation-defined} : @key[constant] Interrupt_Id :=
899 @RI{implementation-defined};
900 @key[end] Ada.Interrupts.Names;
901 @end{example}
902
903 @end{StaticSem}
904
905 @begin{RunTime}
906
907 The Interrupt_Id type is an implementation-defined discrete type used to
908 identify interrupts.
909
910 The Is_Reserved function returns True if and only if the specified
911 interrupt is reserved.
912
913 The Is_Attached function returns True if and only if a user-specified
914 interrupt handler is attached to the interrupt.
915
916 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0069],ARef=[AI95-00166-01]}
917 The Current_Handler function returns a value that represents the
918 attached handler of the interrupt. If no user-defined handler is attached to
919 the interrupt, Current_Handler returns @Chg{New=[@key{null}],
920 Old=[a value that designates the default treatment; calling Attach_Handler
921 or Exchange_Handler with this value restores the default treatment]}.
922
923 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
924 The Attach_Handler procedure attaches the specified handler to the
925 interrupt, overriding any existing treatment (including a user handler)
926 in effect for that interrupt.
927 If New_Handler is @key[null], the default treatment is restored.
928 If New_Handler designates a protected procedure @Chg{Version=[3],New=[for],
929 Old=[to]} which the @Chg{Version=[3],New=[aspect],
930 Old=[pragma]}
931 Interrupt_@!Handler @Chg{Version=[3],New=[is False],Old=[does not apply]},
932 Program_Error is raised. In
933 this case, the operation does not modify the existing interrupt treatment.
934
935 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0069],ARef=[AI95-00166-01]}
936 The Exchange_Handler procedure operates in the same manner as Attach_Handler
937 with the addition that the value returned in Old_Handler designates the
938 previous treatment for the specified interrupt.@Chg{New=[ If the previous
939 treatment is not a user-defined handler, @key[null] is returned.],Old=[]}
940 @begin{Ramification}
941 Calling Attach_Handler or Exchange_Handler with this value for New_Handler
942 restores the previous handler.
943
944 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0069],ARef=[AI95-00166-01]}
945 @ChgAdded{Version=[1],Text=[If the application uses only parameterless procedures as
946 handlers (other types of handlers may be provided by the implementation, but are not
947 required by the standard), then if Old_Handler is not @key(null), it may be
948 called to execute the previous handler. This provides a way to cascade
949 application interrupt handlers. However, the default handler cannot be
950 cascaded this way (Old_Handler must be @key(null) for the default handler).]}
951 @end{Ramification}
952
953 The Detach_Handler procedure restores the default treatment for the
954 specified interrupt.
955
956 For all operations defined in this package that take a parameter of type
957 Interrupt_Id, with the exception of Is_Reserved and Reference, a check is
958 made that the specified interrupt is not reserved.
959 @Defn2{Term=[Program_Error],Sec=(raised by failure of runtime check)}
960 Program_Error is raised if this check fails.
961
962 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
963 If, by using the Attach_Handler, Detach_Handler, or Exchange_Handler
964 procedures, an attempt is made to
965 detach a handler that was attached statically (using the
966 @Chg{Version=[3],New=[aspect],Old=[pragma]}
967 Attach_Handler), the handler is not detached and Program_Error is
968 raised.
969
970 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
971 The Reference function returns a value of type System.Address that can
972 be used to attach a task entry@Chg{Version=[2],New=[],Old=[,]} via an
973 address clause (see @RefSecNum{Interrupt Entries}) to the interrupt
974 specified by Interrupt. This function raises Program_Error if attaching
975 task entries to interrupts (or to this particular interrupt) is not supported.
976
977 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3]}
978 @ChgAdded{Version=[3],Text=[The function Get_CPU returns the processor on which
979 the handler for Interrupt is executed. If the handler can execute on more than
980 one processor the value System.Multiprocessors.Not_A_Specific_CPU is returned.]}
981
982 @end{RunTime}
983
984 @begin{ImplReq}
985
986 At no time during attachment or exchange of handlers shall the current handler
987 of the corresponding interrupt be undefined.
988
989 @end{ImplReq}
990
991 @begin{DocReq}
992
993 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
994 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
995 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0320-1]}
996 @Chg{Version=[5],New=[The implementation shall document, when],Old=[If]}
997 the Ceiling_Locking policy (see @RefSecNum{Priority Ceiling Locking}) is
998 in effect@Chg{Version=[2],New=[,],Old=[]}@Chg{Version=[5],New=[],Old=[
999 the implementation shall document]} the default ceiling priority
1000 assigned to a protected object that contains
1001 @Chg{Version=[3],New=[a protected procedure that specifies ],Old=[]}either
1002 the Attach_Handler or
1003 Interrupt_Handler @Chg{Version=[3],New=[aspects],Old=[pragmas]},
1004 but @Chg{Version=[3],New=[does not specify],Old=[not]} the
1005 Interrupt_Priority @Chg{Version=[3],New=[aspect],Old=[pragma]}.
1006 @Redundant[This default need not be the same for all interrupts.]
1007 @ChgDocReq{Version=[3],Kind=[RevisedAdded],InitialVersion=[2],
1008 Text=[@ChgAdded{Version=[2],
1009 Text=[If the Ceiling_Locking policy is in effect, the default ceiling priority
1010 for a protected object that @Chg{Version=[3],New=[specifies],Old=[contains]}
1011 an interrupt handler @Chg{Version=[3],New=[aspect],Old=[pragma]}.]}]}
1012
1013 @end{DocReq}
1014
1015 @begin{ImplAdvice}
1016
1017 If implementation-defined forms of interrupt handler procedures are supported,
1018 such as protected procedures with parameters, then for each such form of a
1019 handler, a type analogous to Parameterless_@!Handler should be specified in a
1020 child package of Interrupts, with the same operations as in the
1021 predefined package Interrupts.
1022
1023 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1024 Text=[If implementation-defined forms of interrupt handler procedures are
1025 supported, then for each such form of a
1026 handler, a type analogous to Parameterless_@!Handler should be specified in a
1027 child package of Interrupts, with the same operations as in the
1028 predefined package Interrupts.]}]}
1029
1030 @end{ImplAdvice}
1031
1032 @begin{Notes}
1033
1034 The package Interrupts.Names contains implementation-defined
1035 names (and constant values) for the interrupts that are supported by
1036 the implementation.
1037
1038 @end{Notes}
1039
1040 @begin{Examples}
1041 @Leading@Keepnext@i{Example of interrupt handlers:}
1042 @begin{example}
1043 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1044 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0178-1]}
1045 Device_Priority : @key[constant]
1046 @key[array] (@Chg{Version=[5],New=[Ada.Interrupts.Interrupt_Id @key[range] ],Old=[]}1..5) @Chg{Version=[5],New=[@key[of]],Old=[of]}@Chg{Version=[5],New=[
1047 ],Old=[]} System.Interrupt_Priority := ( ... );@Softpage
1048 @key[protected] @key[type] Device_Interface
1049 (Int_Id : Ada.Interrupts.Interrupt_Id) @Chg{Version=[3],New=[
1050 @key[with] Interrupt_Priority => Device_Priority(Int_Id) ],Old=[]}@key[is]
1051 @key[procedure] Handler@Chg{Version=[3],New=[
1052 @key[with] Attach_Handler => Int_Id],Old=[;
1053 @key[pragma] Attach_Handler(Handler, Int_Id)]};
1054 ...
1055 @Chg{Version=[3],New=[],Old=[@key[pragma] Interrupt_Priority(Device_Priority(Int_Id));
1056 ]}@key[end] Device_Interface;@Softpage
1057 ...
1058 Device_1_Driver : Device_Interface(1);
1059 ...
1060 Device_5_Driver : Device_Interface(5);
1061 ...
1062 @end{example}
1063 @end{Examples}
1064
1065 @begin{DiffWord95}
1066 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0069],ARef=[AI95-00166-01]}
1067 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the value
1068 returned by Current_Handler and Exchange_Handler for the default treatment
1069 is null.]}
1070 @end{Diffword95}
1071
1072 @begin{Incompatible2005}
1073 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0167-1]}
1074 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
1075 Function Get_CPU is added to Interrupts. If Interrupts is referenced in
1076 a @nt{use_clause}, and an entity @i<E> with a @nt{defining_identifier} of
1077 Get_CPU is defined in a package that is also referenced in a @nt{use_clause},
1078 the entity @i<E> may no longer be use-visible, resulting in errors. This
1079 should be rare and is easily fixed if it does occur.]}
1080 @end{Incompatible2005}
1081
1082
1083
1084 @ISOOnlyRMNewPageVer{Version=[3]}@Comment{For ISO version of Ada 2012 Standard}
1085 @LabeledClause{Preelaboration Requirements}
1086
1087 @begin{Intro}
1088 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
1089 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]} specifies
1090 additional implementation and documentation
1091 requirements for the Preelaborate pragma (see @RefSecNum{Elaboration Control}).]
1092 @end{Intro}
1093
1094 @begin{ImplReq}
1095
1096 The implementation shall not incur any run-time overhead for the elaboration
1097 checks of subprograms and @ntf{protected_bodies} declared in preelaborated
1098 library units.
1099 @Defn2{Term=[preelaborated],Sec=[implementation requirements]}
1100
1101 The implementation shall not execute any memory write operations after
1102 load time for the elaboration of constant objects
1103 declared immediately within the
1104 declarative region of a preelaborated library package, so long as the
1105 subtype and initial expression (or default initial expressions if
1106 initialized by default) of the @nt<object_declaration> satisfy the
1107 following restrictions.
1108 @Defn{load time}
1109 The meaning of @i{load time} is implementation defined.
1110 @begin{Discussion}
1111 On systems where the image of the partition is initially copied from
1112 disk to RAM, or from ROM to RAM, prior to starting execution of the
1113 partition,
1114 the intention is that @lquotes@;load time@rquotes@; consist of this initial copying
1115 step.
1116 On other systems, load time and run time might actually be interspersed.
1117 @end{Discussion}
1118 @begin{itemize}
1119 Any @nt<subtype_mark> denotes a statically constrained subtype, with
1120 statically constrained subcomponents, if any;
1121
1122 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00161-01]}
1123 @ChgAdded{Version=[2],Text=[no @nt{subtype_mark} denotes a controlled type, a
1124 private type, a private extension, a generic formal private type, a generic
1125 formal derived type, or a descendant of such a type;]}
1126
1127 @begin{Reason}
1128 @ChgRef{Version=[2],Kind=[Added]}
1129 @ChgAdded{Version=[2],Text=[For an
1130 implementation that uses the registration method of finalization, a
1131 controlled object will require some code executed to register the object
1132 at the appropriate point. The other types are those that @i{might} have a
1133 controlled component. None of these types were allowed in preelaborated
1134 units in Ada 95. These types are covered by the @ImplAdviceTitle, of course,
1135 so they should still execute as little code as possible.]}
1136 @end{Reason}
1137
1138 any @nt<constraint> is a static constraint;
1139
1140 any @nt<allocator> is for an access-to-constant type;
1141
1142 any uses of predefined operators appear only within static expressions;
1143
1144 any @ntf<primaries> that are @nt<name>s, other than @nt<attribute_reference>s
1145 for the Access or Address attributes, appear only within static expressions;
1146 @begin{ramification}
1147 This cuts out @nt<attribute_reference>s that are not static, except for
1148 Access and Address.
1149 @end{Ramification}
1150
1151 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0368-1]}
1152 any @nt<name> that is not part of a static expression is an expanded
1153 name or @nt<direct_name> that statically
1154 @Chg{Version=[5],New=[names],Old=[denotes]} some entity;
1155 @begin{Ramification}
1156 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0368-1]}
1157 This cuts out @nt<function_call>s and @nt<type_conversion>s that are not
1158 static, including calls on attribute functions like 'Image and 'Value.@Chg{Version=[5],New=[
1159 We do allow components if those components don't require any evaluation or
1160 checks.],Old=[]}
1161 @end{Ramification}
1162
1163 any @nt<discrete_choice> of an @nt<array_aggregate> is static;
1164
1165 no language-defined check associated with the elaboration of the
1166 @nt<object_declaration> can fail.
1167 @begin{Reason}
1168 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1169 The intent is that aggregates all of whose scalar subcomponents are static@Chg{Version=[2],New=[],Old=[,]}
1170 and all of whose access subcomponents are @key(null), allocators for
1171 access-to-constant types, or X'Access, will be supported with no run-time
1172 code generated.
1173 @end{Reason}
1174 @end{itemize}
1175
1176 @end{ImplReq}
1177
1178 @begin{DocReq}
1179
1180 The implementation shall document any circumstances under which the
1181 elaboration of a preelaborated package causes code to be executed at run time.
1182 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1183 Text=[Any circumstances when the elaboration of a preelaborated package
1184 causes code to be executed.]}]}
1185
1186 The implementation shall document whether the method used for initialization
1187 of preelaborated variables allows a partition to be restarted without
1188 reloading.
1189 @ChgDocReq{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
1190 Text=[Whether a partition can be restarted without reloading.]}]}
1191 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
1192 Text=[@ChgDeleted{Version=[2],
1193 Text=[Implementation-defined aspects of preelaboration.]}]}
1194 @begin{discussion}
1195 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
1196 This covers the issue of the @Chg{Version=[2],New=[run-time system],Old=[RTS]}
1197 itself being restartable,
1198 so that need not be a separate @DocReqName.
1199 @end{discussion}
1200
1201 @end{DocReq}
1202
1203 @begin{ImplAdvice}
1204
1205 It is recommended that preelaborated packages be implemented in such a
1206 way that there should be little or no code executed at run time for the
1207 elaboration of entities not already covered by the @ImplReqName@;s.
1208
1209 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1210 Text=[Preelaborated packages should be implemented such that little or no
1211 code is executed at run time for the elaboration of entities.]}]}
1212 @end{ImplAdvice}
1213
1214 @begin{DiffWord95}
1215 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00161-01]}
1216 @ChgAdded{Version=[2],Text=[Added wording to exclude the additional kinds
1217 of types allowed in preelaborated units from the @ImplReqTitle.]}
1218 @end{DiffWord95}
1219
1220 @begin{DiffWord2012}
1221 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0368-1]}
1222 @ChgAdded{Version=[5],Text=[Added wording to allow components so long as
1223 no evaluation or checks are required for the reference.]}
1224 @end{DiffWord2012}
1225
1226
1227 @LabeledRevisedClause{Version=[4],New=[Aspect Discard_Names],
1228 Old=[Pragma Discard_Names]}
1229
1230 @begin{Intro}
1231 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1232 @Redundant[@Chg{Version=[4],New=[Specifying the aspect],Old=[A @nt{pragma}]}
1233 Discard_Names @Chg{Version=[4],New=[can],Old=[may]} be used to request a
1234 reduction in storage used for the names of
1235 @Chg{Version=[4],New=[],Old=[certain ]}entities@Chg{Version=[4],New=[ with
1236 runtime name text],Old=[]}.]
1237 @end{Intro}
1238
1239 @begin{StaticSem}
1240 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0072-1]}
1241 @ChgAdded{Version=[4],Text=[An entity with @i{runtime name text} is a
1242 nonderived enumeration first subtype, a tagged first subtype, or an
1243 exception.@Defn{entity with runtime name text}@Defn2{Term=[runtime name text],Sec=[entity with]}]}
1244
1245 @ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0072-1]}
1246 @ChgAdded{Version=[4],Type=[Leading],Text=[For an entity with runtime name
1247 text, the following language-defined representation aspect may be specified:]}
1248
1249 @begin{Description}
1250 @ChgRef{Version=[4],Kind=[Added]}
1251 @ChgAdded{Version=[4],Text=[Discard_Names@\The type of aspect Discard_Names
1252 is Boolean. If directly specified, the @nt{aspect_definition} shall be
1253 a static expression. If not specified (including by inheritance), the
1254 aspect is False.@AspectDefn{Discard_Names}]}
1255
1256 @ChgAspectDesc{Version=[4],Kind=[Added],Aspect=[Discard_Names],
1257 Text=[@ChgAdded{Version=[4],Text=[Requests a reduction in storage for names associated
1258 with an entity.]}]}
1259 @end{Description}
1260 @end{StaticSem}
1261
1262 @begin{Syntax}
1263 @begin{SyntaxText}
1264 @Leading@Keepnext@;The form of a @nt{pragma} Discard_Names is as follows:
1265 @end{SyntaxText}
1266
1267 @PragmaSyn`@key{pragma} @prag(Discard_Names)[([On => ] @Syn2[local_name])];'
1268
1269 @begin{SyntaxText}
1270 A @nt{pragma} Discard_Names is allowed only immediately within a
1271 @nt{declarative_part}, immediately within a @nt{package_specification},
1272 or as a configuration pragma.
1273 @PDefn2{Term=[configuration pragma], Sec=(Discard_Names)}
1274 @PDefn2{Term=[pragma, configuration], Sec=(Discard_Names)}
1275 @end{SyntaxText}
1276 @end{Syntax}
1277
1278 @begin{Legality}
1279 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1280 The @nt{local_name} (if present) shall denote
1281 @Chg{Version=[4],New=[an entity with runtime name text],Old=[a nonderived
1282 enumeration @Redundant[first] subtype,
1283 a tagged @Redundant[first] subtype, or an exception]}.
1284 The pragma @Chg{Version=[4],New=[specifies that the aspect Discard_Names
1285 for],Old=[applies to]} the type or
1286 exception@Chg{Version=[4],New=[ has the value True],Old=[]}.
1287 Without a @nt{local_name}, the pragma @Chg{Version=[4],New=[specifies that],
1288 Old=[applies to]} all
1289 @Chg{Version=[4],New=[],Old=[such ]}entities@Chg{Version=[4],New=[ with
1290 runtime name text],Old=[]}
1291 declared after the pragma, within the same declarative
1292 region@Chg{Version=[4],New=[ have the value True for aspect
1293 Discard_Names],Old=[]}.
1294 Alternatively, the pragma can be used as a configuration pragma.
1295 @Chg{Version=[4],New=[If the configuration pragma Discard_Names applies to a
1296 compilation unit, all entities with runtime name text declared in the
1297 compilation unit have the value True for the aspect Discard_Names.],Old=[If the
1298 pragma applies to a type, then it applies also to all descendants of the type]}.
1299
1300 @begin{Ramification}
1301 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0072-1]}
1302 @ChgAdded{Version=[4],Text=[If the aspect is specified for a type, then
1303 it is inherited by all descendants of the type. The aspect cannot be
1304 specified as False on a derived type (because specifying the aspect is
1305 not allowed on derived enumeration types, and by rule applying to all
1306 aspects for other types (see @RefSecNum{Aspect Specifications})).]}
1307 @end{Ramification}
1308
1309 @end{Legality}
1310
1311 @begin{StaticSem}
1312 @PDefn2{Term=[representation pragma], Sec=(Discard_Names)}
1313 @PDefn2{Term=[pragma, representation], Sec=(Discard_Names)}
1314 If a @nt{local_name} is given, then
1315 a @nt{pragma} Discard_Names is a representation pragma.
1316
1317 @begin{Ramification}
1318 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
1319 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0072-1]}@ChgNote{Explicit now.}
1320 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[Representation
1321 pragmas automatically specify aspects of the same name,
1322 so Discard_Names can be used as an @nt{aspect_mark} in an
1323 @nt{aspect_specification} instead of using the pragma on individual
1324 entities.],Old=[]}]}
1325 @end{Ramification}
1326
1327 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01],ARef=[AI95-00400-01]}
1328 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1329 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1330 for],Old=[pragma applies to]} an enumeration type,
1331 then the semantics of the @Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1332 and @Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} attributes
1333 are implementation defined for that type@Redundant[; the
1334 semantics of Image@Chg{Version=[2],New=[, Wide_Image,],Old=[ and]}
1335 Value@Chg{Version=[2],New=[, and Wide_Value],Old=[]} are still defined in
1336 terms of @Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1337 and @Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]}].
1338 In addition, the semantics of Text_IO.Enumeration_IO are implementation
1339 defined.
1340 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1341 for],Old=[pragma applies to]} a tagged type,
1342 then the semantics of the Tags.@!@Chg{Version=[2],New=[Wide_Wide_@!Expanded_@!Name],
1343 Old=[Expanded_@!Name]} function
1344 are implementation defined for that type@Chg{Version=[2],New=[@Redundant[; the
1345 semantics of Tags.@!Expanded_@!Name and Tags.@!Wide_@!Expanded_@!Name are still
1346 defined in terms of Tags.@!Wide_Wide_@!Expanded_@!Name]], Old=[]}.
1347 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1348 for],Old=[pragma applies to]} an exception,
1349 then the semantics of the Exceptions.@!@Chg{Version=[2],New=[Wide_Wide_@!Exception_@!Name],
1350 Old=[Exception_@!Name]} function
1351 are implementation defined for that exception@Chg{Version=[2],New=[@Redundant[; the
1352 semantics of Exceptions.@!Exception_@!Name and Exceptions.@!Wide_@!Exception_@!Name
1353 are still defined in terms of Exceptions.@!Wide_Wide_@!Exception_@!Name]], Old=[]}.
1354
1355 @ChgImplDef{Version=[4],Kind=[Revised],InitialVersion=[0],
1356 Text=[The semantics of @Chg{Version=[4],New=[some attributes and functions of
1357 an entity for which aspect],Old=[pragma]}
1358 Discard_Names@Chg{Version=[4],New=[ is True],Old=[]}.]}
1359 @begin{Ramification}
1360 The Width attribute is still defined in terms of Image.
1361
1362 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
1363 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1364 The semantics of S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]}
1365 and S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} are
1366 implementation defined for any subtype of an enumeration type
1367 @Chg{Version=[4],New=[for],Old=[to]} which
1368 the @Chg{Version=[4],New=[aspect is True],Old=[pragma applies]}.
1369 (The pragma@Chg{Version=[4],New=[, if used,],Old=[]} actually names
1370 the first subtype, of course.)
1371 @end{Ramification}
1372 @end{StaticSem}
1373
1374 @begin{ImplAdvice}
1375 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0072-1]}
1376 If the @Chg{Version=[4],New=[aspect Discard_Names is True
1377 for],Old=[pragma applies to]} an entity, then the implementation should
1378 reduce the amount of storage used for storing names associated with that
1379 entity.
1380 @ChgImplAdvice{Version=[4],Kind=[Revised],InitialVersion=[2],
1381 Text=[@ChgAdded{Version=[2],
1382 Text=[If @Chg{Version=[4],New=[aspect],Old=[@nt{pragma}]} Discard_Names
1383 @Chg{Version=[4],New=[is True for],Old=[applies to]} an entity, then
1384 the amount of storage used for storing names associated with that entity
1385 should be reduced.]}]}
1386 @begin{Reason}
1387 A typical implementation of the Image attribute for enumeration types is
1388 to store a table containing the names of all the enumeration literals.
1389 @Chg{Version=[4],New=[Aspect],Old=[Pragma]} Discard_Names allows the
1390 implementation to avoid storing such a
1391 table without having to prove that the Image attribute is never used
1392 (which can be difficult in the presence of separate compilation).
1393
1394 We did not specify the semantics of the Image attribute
1395 @Chg{Version=[4],New=[when aspect Discard_Names is True],Old=[in the presence
1396 of this pragma]} because different semantics might be desirable in
1397 different situations.
1398 In some cases, it might make sense to use the Image attribute to print
1399 out a useful value that can be used to identify the entity given
1400 information in compiler-generated listings.
1401 In other cases, it might make sense to get an error at compile time or
1402 at run time.
1403 In cases where memory is plentiful, the simplest implementation makes
1404 sense: ignore the @Chg{Version=[4],New=[aspect],Old=[pragma]}.
1405 Implementations that are capable of avoiding the extra storage in cases
1406 where the Image attribute is never used might also wish to ignore the
1407 @Chg{Version=[4],New=[aspect],Old=[pragma]}.
1408
1409 The same applies to the Tags.Expanded_Name and Exceptions.Exception_Name
1410 functions.
1411 @end{Reason}
1412 @end{ImplAdvice}
1413
1414 @begin{DiffWord95}
1415 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00400-01]}
1416 @ChgAdded{Version=[2],Text=[Updated the wording to reflect that the double
1417 wide image and value functions are now the master versions that the others
1418 are defined from.]}
1419 @end{DiffWord95}
1420
1421 @begin{DiffWord2012}
1422 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0072-1]}
1423 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Defined the pragma in terms of
1424 the aspect Discard_Names, and added a missing definition of the meaning of
1425 the configuration pragma. This is not intended to make any semantic change
1426 (Ada 2012 has an aspect Discard_Names defined via blanket rules for
1427 representation pragmas in @RefSecNum{Operational and Representation Aspects}
1428 and @RefSecNum{Aspect Specifications}), just to clarify the meaning.]}
1429 @end{DiffWord2012}
1430
1431
1432 @LabeledClause{Shared Variable Control}
1433
1434 @begin{Intro}
1435 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1],ARef=[AI05-0299-1]}
1436 @Redundant[This @Chg{Version=[3],New=[subclause defines],Old=[clause specifies]}
1437 representation @Chg{Version=[3],New=[aspects],Old=[pragmas]} that control the
1438 use of shared variables.]
1439 @end{Intro}
1440
1441 @begin{NotIso}
1442 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2
1443 through 6 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1444 should be deleted if the paragraphs are ever renumbered.}
1445 @end{NotIso}
1446
1447 @begin{Syntax}
1448 @begin{SyntaxText}
1449 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1450 @ChgDeleted{Version=[3],Type=[Leading],Text=[The form for pragmas Atomic,
1451 Volatile, Atomic_Components, and Volatile_Components is as follows:]}
1452 @end{SyntaxText}
1453
1454 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1455 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1456 Text=[@key{pragma} @prag(Atomic)(@Syn2{local_name});]}>
1457
1458 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1459 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1460 Text=[@key{pragma} @prag(Volatile)(@Syn2{local_name});]}>
1461
1462 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1463 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1464 Text=[@key{pragma} @prag(Atomic_Components)(@SynI{array_}@Syn2{local_name});]}>
1465
1466 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg]}
1467 @DeletedPragmaSyn<Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3],
1468 Text=[@key{pragma} @prag(Volatile_Components)(@SynI{array_}@Syn2{local_name});]}>
1469
1470 @end{Syntax}
1471
1472 @Comment{Original: @begin{Intro}, Replaced with below for Ada 2012}
1473 @begin{StaticSem}
1474
1475 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1476 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0282-1]}
1477 @ChgAdded{Version=[3],Type=[Leading],Text=[For an @nt{object_declaration}, a
1478 @nt{component_declaration}, @Chg{Version=[5],New=[],Old=[or ]}a
1479 @nt{full_type_declaration}, @Chg{Version=[5],New=[or a
1480 @nt{formal_complete_type_declaration}, ],Old=[]}the following
1481 representation aspects may be specified:]}
1482
1483 @begin{Description}
1484 @ChgRef{Version=[3],Kind=[Added]}
1485 @ChgAdded{Version=[3],Text=[Atomic@\The type of aspect Atomic is
1486 Boolean.@AspectDefn{Atomic}]}
1487
1488 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Atomic],
1489 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component is
1490 atomic.]}]}
1491
1492 @ChgRef{Version=[3],Kind=[Added]}
1493 @ChgAdded{Version=[3],Text=[Independent@\The type of aspect Independent is
1494 Boolean.@AspectDefn{Independent}]}
1495
1496 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Independent],
1497 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component
1498 is independently addressable.]}]}
1499
1500 @ChgRef{Version=[3],Kind=[Added]}
1501 @ChgAdded{Version=[3],Text=[Volatile@\The type of aspect Volatile is
1502 Boolean.@AspectDefn{Volatile}]}
1503
1504 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Volatile],
1505 Text=[@ChgAdded{Version=[3],Text=[Declare that a type, object, or component
1506 is volatile.]}]}
1507
1508 @end{Description}
1509
1510 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1511 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0282-1]}
1512 @ChgAdded{Version=[3],Type=[Leading],Text=[For a @nt{full_type_declaration} of
1513 an array type@Chg{Version=[5],New=[,],Old=[ (including the anonymous type of]}
1514 an @nt{object_declaration}
1515 @Chg{Version=[5],New=[for an object of an anonymous array type, or the
1516 @nt{formal_complete_type_declaration} of a formal array type],Old=[of an
1517 anonymous array object)]}, the following representation aspects may be
1518 specified:]}
1519
1520 @begin{Description}
1521 @ChgRef{Version=[3],Kind=[Added]}
1522 @ChgAdded{Version=[3],Text=[Atomic_Components@\The type of aspect
1523 Atomic_Components is Boolean.@AspectDefn{Atomic_Components}]}
1524
1525 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Atomic_Components],
1526 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of
1527 an array type or object are atomic.]}]}
1528
1529 @ChgRef{Version=[3],Kind=[Added]}
1530 @ChgAdded{Version=[3],Text=[Volatile_Components@\The type of aspect
1531 Volatile_Components is Boolean.@AspectDefn{Volatile_Components}]}
1532
1533 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Volatile_Components],
1534 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of
1535 an array type or object are volatile.]}]}
1536
1537 @end{Description}
1538
1539 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1540 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0282-1]}
1541 @ChgAdded{Version=[3],Type=[Leading],Text=[For a @nt{full_type_declaration}
1542 @Chg{Version=[5],New=[of a composite type,],Old=[ (including the anonymous type of]}
1543 an @nt{object_declaration}
1544 @Chg{Version=[5],New=[for an object of an anonymous composite type, or the
1545 @nt{formal_complete_type_declaration} of a formal composite type],Old=[of an
1546 anonymous array object)]}, the following representation aspect may be
1547 specified:]}
1548
1549 @begin{Description}
1550 @ChgRef{Version=[3],Kind=[Added]}
1551 @ChgAdded{Version=[3],Text=[Independent_Components@\The type of aspect
1552 Independent_Components is Boolean.@AspectDefn{Independent_Components}]}
1553
1554 @ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Independent_Components],
1555 Text=[@ChgAdded{Version=[3],Text=[Declare that the components of an array
1556 or record type, or an array object, are independently addressable.]}]}
1557
1558 @end{Description}
1559
1560 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1561 @ChgAdded{Version=[3],Text=[If any of these aspects are directly
1562 specified, the @nt{aspect_definition} shall be a static expression. If not
1563 specified (including by inheritance), each of these aspects is False.]}
1564
1565 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00272-01]}
1566 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1567 @Defn{atomic}
1568 An @i{atomic} type is one @Chg{Version=[3],New=[for],Old=[to]} which
1569 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic
1570 @Chg{Version=[3],New=[is True],Old=[applies]}.
1571 An @i{atomic} object (including a component)
1572 is one @Chg{Version=[3],New=[for],Old=[to]} which
1573 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic
1574 @Chg{Version=[3],New=[is True],Old=[applies]},
1575 or a component of an array @Chg{Version=[3],New=[for],Old=[to]} which
1576 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Atomic_Components
1577 @Chg{Version=[3],New=[is True for the associated type],Old=[applies]},
1578 or any object of an atomic type@Chg{Version=[2],
1579 New=[, other than objects obtained by evaluating a slice],Old=[]}.
1580 @begin{Ramification}
1581 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00272-01]}
1582 @ChgAdded{Version=[2],Text=[A slice of an atomic array object is not itself
1583 atomic. That's necessary as executing a read or write of a dynamic number
1584 of components in a single instruction is not possible on many targets.]}
1585 @end{Ramification}
1586
1587 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1588 @Defn{volatile}
1589 A @i{volatile} type is one @Chg{Version=[3],New=[for],Old=[to]} which
1590 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile
1591 @Chg{Version=[3],New=[is True],Old=[applies]}.
1592 A @i{volatile} object (including a component)
1593 is one @Chg{Version=[3],New=[for],Old=[to]} which
1594 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile
1595 @Chg{Version=[3],New=[is True],Old=[applies]},
1596 or a component of an array @Chg{Version=[3],New=[for],Old=[to]} which
1597 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Volatile_@!Components
1598 @Chg{Version=[3],New=[is True for the associated type],Old=[applies]},
1599 or any object of a volatile type.
1600 In addition, every atomic type or object is also defined to be volatile.
1601 Finally, if an object is volatile, then so
1602 are all of its subcomponents @Redundant[(the same does not apply to atomic)].
1603
1604 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1605 @ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0001-1]}
1606 @ChgAdded{Version=[3],Text=[When True, the aspects Independent and
1607 Independent_Components @i<specify as independently addressable> the named object
1608 or component(s), or in the case of a type, all objects or components
1609 of that type. All atomic objects @Chg{Version=[4],New=[and aliased
1610 objects ],Old=[]}are considered to be specified as independently
1611 addressable.@Defn{specified as independently addressable}@Defn2{Term=[independently addressable],Sec=[specified]}]}
1612
1613 @begin{Ramification}
1614 @ChgRef{Version=[3],Kind=[AddedNormal]}
1615 @ChgAdded{Version=[3],Text=[If the compiler cannot guarantee that an object
1616 (including a component) for which aspect Independent or aspect
1617 Independent_Components is True is independently addressable from
1618 any other nonoverlapping object, then the aspect specification
1619 must be rejected.]}
1620
1621 @ChgRef{Version=[3],Kind=[AddedNormal]}
1622 @ChgAdded{Version=[3],Text=[Similarly, an atomic object (including atomic
1623 components) is always independently addressable from any other nonoverlapping
1624 object. Any representation item which would prevent this from being true should
1625 be rejected, notwithstanding what this Standard says elsewhere (specifically,
1626 in the Recommended Level of Support).]}
1627 @end{Ramification}
1628
1629 @Comment{Original: @end{Intro}, Replaced with below for Ada 2012}
1630 @end{StaticSem}
1631
1632 @begin{NotIso}
1633 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 9
1634 was moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1635 should be deleted if the paragraphs are ever renumbered.}@ChgNote{We use
1636 this message rather than the "automatic one" to get rid of the resolution
1637 subheader}
1638 @end{NotIso}
1639
1640 @begin{Resolution}
1641 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1642 @ChgDeleted{Version=[3],Text=[The @nt{local_name} in an Atomic or Volatile
1643 pragma shall resolve to denote either an @nt{object_declaration}, a
1644 noninherited @nt{component_@!declaration}, or a @nt{full_type_@!declaration}.
1645 The @SynI{array_}@nt{local_name} in an Atomic_@!Components or
1646 Volatile_@!Components pragma shall resolve to denote the declaration of an array
1647 type or an array object of an anonymous type.]}
1648 @end{Resolution}
1649
1650 @begin{Legality}
1651
1652 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}
1653 @ChgAdded{Version=[3],Text=[If aspect Independent_Components is specified for a
1654 @nt{full_type_declaration}, the declaration shall be that of an array or record
1655 type.]}
1656
1657 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1658 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
1659 @Defn{indivisible}
1660 It is illegal to @Chg{Version=[3],New=[specify],Old=[apply]}
1661 either @Chg{Version=[3],New=[of the aspects],Old=[an]} Atomic or
1662 Atomic_Components @Chg{Version=[3],New=[],Old=[pragma ]}to
1663 @Chg{Version=[3],New=[have the value True for ],Old=[]}an
1664 object or type if the implementation cannot support the indivisible
1665 @Chg{Version=[4],New=[and independent ],Old=[]}reads
1666 and updates required by the @Chg{Version=[3],New=[aspect],Old=[pragma]}
1667 (see below).
1668
1669 @ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0001-1]}
1670 It is illegal to specify the Size attribute of an atomic object, the
1671 Component_Size attribute for an array type with atomic components, or the layout
1672 attributes of an atomic component, in a way that prevents the implementation
1673 from performing the required indivisible
1674 @Chg{Version=[4],New=[and independent ],Old=[]}reads and updates.
1675
1676 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0218-1]}
1677 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0282-1]}
1678 If an atomic object is passed as a parameter, then
1679 @Chg{Version=[3],New=[],Old=[the type of ]}the formal
1680 parameter shall either @Chg{Version=[3],New=[have an],Old=[be]} atomic
1681 @Chg{Version=[3],New=[type ],Old=[]}or allow pass by
1682 copy@Chg{Version=[3],New=[],Old=[ @Redundant[(that
1683 is, not be a nonatomic by-reference type)]]}. If an atomic object is used
1684 as an actual for a generic formal object of mode @key{in out}, then the
1685 type of the generic formal object shall be atomic. If the @nt<prefix> of
1686 an @nt<attribute_reference> for an Access attribute denotes an atomic
1687 object @Redundant[(including a component)], then the designated type of
1688 the resulting access type shall be atomic.@Chg{Version=[5],New=[],Old=[ If an
1689 atomic type is used as an actual for a generic formal derived type,
1690 then the ancestor of the formal type
1691 shall be atomic@Chg{Version=[3],New=[],Old=[ or allow pass by copy]}.]}
1692 Corresponding rules apply to volatile objects@Chg{Version=[5],New=[],Old=[ and types]}.
1693
1694 @begin{Ramification}
1695 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
1696 @ChgAdded{Version=[3],Text=[A formal parameter allows pass by copy
1697 if it is not @key[aliased] and it is of a type that allows pass by copy (that
1698 is, is not a by-reference type).]}
1699 @end{Ramification}
1700
1701 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0218-1]}
1702 @ChgRef{Version=[5],Kind=[RevisedAdded],ARef=[AI12-0282-1]}
1703 @ChgAdded{Version=[3],Text=[If @Chg{Version=[5],New=[the Atomic,
1704 Atomic_Components, Volatile, Volatile_Components, Independent, or
1705 Independent_Components aspect is True for a generic formal type, then that
1706 aspect shall be True for the actual type. If ],Old=[]}a volatile type is used
1707 as an actual for a generic formal array type, then the element type of the
1708 formal type shall be volatile.@Chg{Version=[5],New=[ If an
1709 atomic type is used as an actual for a generic formal derived type,
1710 then the ancestor of the formal type shall be atomic. A corresponding
1711 rule applies to volatile types.],Old=[]}]}
1712
1713 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1714 If @Chg{Version=[3],New=[an aspect],Old=[a pragma]} Volatile,
1715 Volatile_Components, Atomic, or Atomic_Components
1716 @Chg{Version=[3],New=[is directly specified to have the value
1717 True for],Old=[applies to]} a stand-alone constant object, then
1718 @Chg{Version=[3],New=[the aspect],Old=[a pragma]} Import shall
1719 also @Chg{Version=[3],New=[be specified as True for],Old=[apply to]} it.
1720 @begin{Ramification}
1721 Hence, no initialization expression is allowed for such a constant. Note
1722 that a constant that is atomic or volatile because of its type is allowed.
1723 @end{Ramification}
1724 @begin{Reason}
1725 Stand-alone constants that are explicitly specified as Atomic or Volatile
1726 only make sense if they are being manipulated outside the Ada program.
1727 From the Ada perspective the object is read-only. Nevertheless, if
1728 imported and atomic or volatile, the implementation should presume it
1729 might be altered externally.
1730 For an imported stand-alone constant that is not atomic or
1731 volatile, the implementation can assume that it will not be
1732 altered.
1733 @end{Reason}
1734 @begin{Honest}
1735 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0218-1]}
1736 @ChgAdded{Version=[3],Text=[Volatile_Components and Atomic_Components actually
1737 are aspects of the anonymous array type; this rule only applies when the
1738 aspect is specified directly on the constant object and not when the (named)
1739 array type has the aspect.]}
1740 @end{Honest}
1741
1742 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1743 @ChgAdded{Version=[3],Text=[It is illegal to specify the aspect Independent or
1744 Independent_Components as True for a component, object or type if the
1745 implementation cannot provide the independent addressability required by the
1746 aspect (see @RefSecNum{Shared Variables}).]}
1747
1748 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
1749 @ChgAdded{Version=[3],Text=[It is illegal to specify a representation aspect for
1750 a component, object or type for which the aspect Independent or
1751 Independent_Components is True, in a way that prevents the implementation from
1752 providing the independent addressability required by the aspect.]}
1753
1754 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0128-1]}
1755 @ChgAdded{Version=[5],Text=[If a nonatomic subcomponent of an atomic object is
1756 passed as the actual parameter in a call then the formal parameter shall allow
1757 pass by copy (and, at run time, the parameter shall be passed by copy). A
1758 nonatomic subcomponent of an atomic object shall not be used as an actual for a
1759 generic formal of mode @key[in out]. A nonatomic subcomponent of an atomic type
1760 shall not be aliased. A nonatomic subcomponent of an atomic type or object shall
1761 not have components that are specified to be independently addressable.]}
1762
1763 @end{Legality}
1764
1765 @begin{NotIso}
1766 @ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 14
1767 was moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message
1768 should be deleted if the paragraphs are ever renumbered.}@ChgNote{We use
1769 this message rather than the "automatic one" to get rid of the static semantics
1770 subheader}
1771 @end{NotIso}
1772
1773 @begin{StaticSem}
1774 @ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]}
1775 @ChgDeleted{Version=[3],Text=[@PDefn2{Term=[representation pragma], Sec=(Atomic)}
1776 @PDefn2{Term=[pragma, representation], Sec=(Atomic)}
1777 @PDefn2{Term=[representation pragma], Sec=(Volatile)}
1778 @PDefn2{Term=[pragma, representation], Sec=(Volatile)}
1779 @PDefn2{Term=[representation pragma], Sec=(Atomic_Components)}
1780 @PDefn2{Term=[pragma, representation], Sec=(Atomic_Components)}
1781 @PDefn2{Term=[representation pragma], Sec=(Volatile_Components)}
1782 @PDefn2{Term=[pragma, representation], Sec=(Volatile_Components)}
1783 These @nt{pragma}s are representation pragmas
1784 (see @RefSecNum{Operational and Representation Aspects}).]}
1785 @end{StaticSem}
1786
1787 @begin{RunTime}
1788
1789 For an atomic object (including an atomic component) all reads and
1790 updates of the object as a whole are indivisible.
1791
1792 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
1793 @Chg{Version=[3],New=[All tasks of the program (on all processors) that
1794 read or update volatile variables see the same order of
1795 updates to the variables. A use of an atomic variable or other mechanism may be
1796 necessary to avoid erroneous execution and to ensure that access to
1797 nonatomic volatile variables is sequential (see @RefSecNum{Shared Variables}).],
1798 Old=[For a volatile object all reads and updates of the object as a whole are
1799 performed directly to memory.]}
1800
1801 @begin{ImplNote}
1802 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
1803 @Chg{Version=[3],New=[To ensure this, on a multiprocessor, any read or
1804 update of an atomic object may require the use of an appropriate memory
1805 barrier.],Old=[This precludes any use of register temporaries,
1806 caches, and other similar optimizations for that object.]}
1807 @end{ImplNote}
1808
1809 @begin{Discussion}
1810 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1811 @ChgAdded{Version=[3],Text=[From @RefSecNum{Shared Variables} it follows that
1812 (in non-erroneous programs) accesses to variables, including those shared by
1813 multiple tasks, are always sequential. This guarantees that no task will ever
1814 see partial updates of any variable. For volatile variables (including atomic
1815 variables), the above rule additionally specifies that all tasks see the same
1816 order of updates.]}
1817
1818 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1819 @ChgAdded{Version=[3],Text=[If for a shared variable @i<X>, a read of @i<X>
1820 occurs sequentially after an update of @i<X>, then the read will return the
1821 updated value if @i<X> is volatile or atomic, but may or or may not return the
1822 updated value if @i<X> is nonvolatile. For nonvolatile accesses, a signaling
1823 action is needed in order to share the updated value.]}
1824
1825 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0275-1]}
1826 @ChgAdded{Version=[3],Text=[Because accesses to the same atomic variable by
1827 different tasks establish a sequential order between the actions of those tasks,
1828 implementations may be required to emit memory barriers around such updates or
1829 use atomic instructions that imply such barriers.]}
1830 @end{Discussion}
1831
1832 @Defn2{Term=[sequential], Sec=(actions)}
1833 Two actions are sequential (see @RefSecNum{Shared Variables}) if each
1834 is the read or update of the same atomic object.
1835
1836 @PDefn2{Term=[by-reference type], Sec=(atomic or volatile)}
1837 If a type is atomic or volatile and it is not a by-copy type, then the type
1838 is defined to be a by-reference type. If any subcomponent of a type is
1839 atomic or volatile, then the type is defined to be a by-reference type.
1840
1841 If an actual parameter is atomic or volatile, and the corresponding
1842 formal parameter is not, then the parameter is passed by copy.
1843 @begin{ImplNote}
1844 Note that in the case where such a parameter is normally passed by
1845 reference, a copy of the actual will have to be produced at the call-site,
1846 and a pointer to the copy passed to the formal parameter. If the actual
1847 is atomic, any copying has to use indivisible read on the way in, and
1848 indivisible write on the way out.
1849 @end{ImplNote}
1850 @begin{Reason}
1851 It has to be known at compile time whether an atomic or a volatile parameter
1852 is to be passed by copy or by reference. For some types, it is unspecified
1853 whether parameters are passed by copy or by reference. The above rules
1854 further specify the parameter passing rules involving atomic and volatile
1855 types and objects.
1856 @end{Reason}
1857
1858 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0128-1],ARef=[AI12-0347-1]}
1859 @ChgAdded{Version=[5],Text=[All reads of or writes to any nonatomic subcomponent
1860 of an atomic object are performed by reading and/or writing all of the
1861 nearest enclosing atomic object.]}
1862
1863 @begin{ImplNote}
1864 @ChgRef{Version=[5],Kind=[AddedNormal]}
1865 @ChgAdded{Version=[5],Text=[For example, if a 32-bit record object has four
1866 nonatomic components, each occupying one byte, then an assignment to one of
1867 those components might normally be implemented on some target machines via
1868 some sort of store_byte instruction; if the record object is atomic then
1869 instead a 32-bit read-modify-write must be performed.
1870 That read-modify-write need not be atomic, although the read
1871 and the write must each separately be atomic. Note that it doesn't
1872 matter whether the store_byte instruction would have executed atomically.
1873 This rule is needed in some cases for memory-mapped device registers.]}
1874 @end{ImplNote}
1875
1876 @end{RunTime}
1877
1878 @begin{ImplReq}
1879
1880 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0128-1]}
1881 @PDefn2{Term=[external effect], Sec=(volatile/atomic objects)}
1882 The external effect of a program
1883 (see @RefSecNum(Conformity of an Implementation with the Standard))
1884 is defined to include each read and update
1885 of a volatile or atomic object. The implementation shall not
1886 generate any memory reads or updates of atomic or volatile
1887 objects other than those specified by the program.@Chg{Version=[5],New=[
1888 However, there may be target-dependent cases where reading or writing a
1889 volatile but nonatomic object (typically a component) necessarily involves
1890 reading and/or writing neighboring storage, and that neighboring storage might
1891 overlap a volatile object.],Old=[]}
1892 @begin{Discussion}
1893 The presumption is that volatile or atomic objects might reside in an
1894 @lquotes@;active@rquotes@; part of the address space where each read has a
1895 potential side effect, and at the very least might deliver a different value.
1896
1897 @Leading@;The rule above and the definition of external effect are intended to
1898 prevent (at least) the following incorrect optimizations, where V is
1899 a volatile variable:
1900 @begin{itemize}
1901 X:= V; Y:=V; cannot be allowed to be translated as Y:=V; X:=V;
1902
1903 Deleting redundant loads: X:= V; X:= V; shall read the value of V from
1904 memory twice.
1905
1906 Deleting redundant stores: V:= X; V:= X; shall write into V twice.
1907
1908 Extra stores: V:= X+Y; should not translate to something like V:= X; V:= V+Y;
1909
1910 Extra loads: X:= V; Y:= X+Z; X:=X+B; should not translate to something like
1911 Y:= V+Z; X:= V+B;
1912
1913 Reordering of loads from volatile variables: X:= V1; Y:= V2; (whether or not
1914 V1 = V2) should not translate to Y:= V2; X:= V1;
1915
1916 Reordering of stores to volatile variables: V1:= X; V2:= X; should not
1917 translate to V2:=X; V1:= X;
1918 @end{itemize}
1919
1920 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0128-1]}
1921 @ChgAdded{Version=[5],Text=[The part about @ldquote@;target-dependent
1922 cases@rdquote is intended to let compilers use a read-modify-write operation
1923 when a volatile component has a size that cannot be directly read or written
1924 with the available machine instructions. (For instance, writing a Boolean
1925 component with size 1 in a volatile packed array of Boolean requires a
1926 pre-read on most existing machines.)]}
1927 @end{Discussion}
1928
1929 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]}
1930 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
1931 @ChgDeleted{Version=[4],Text=[If @Chg{Version=[3],New=[the],Old=[a pragma]} Pack
1932 @Chg{Version=[3],New=[aspect is True for],Old=[applies to]} a type any of whose
1933 subcomponents are atomic,
1934 the implementation shall not pack the atomic subcomponents more tightly
1935 than that for which it can support indivisible reads and updates.]}
1936 @begin{ImplNote}
1937 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0009-1]}
1938 @ChgRef{Version=[4],Kind=[Deleted],ARef=[AI12-0001-1]}
1939 @ChgDeleted{Version=[4],Text=[@Chg{Version=[3],New=[Usually, specifying aspect Pack for such a type
1940 will be illegal as the Recommended Level of Support cannot be achieved;
1941 otherwise, a],Old=[A]} warning might be appropriate if
1942 no packing whatsoever can be achieved.]}
1943 @end{ImplNote}
1944 @end{ImplReq}
1945
1946 @begin{ImplPerm}
1947 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0282-1]}
1948 @ChgAdded{Version=[5],Text=[Within the body of an instance of a generic unit
1949 that has a formal type @i<T> that is not atomic and an actual type that is
1950 atomic, if an object @i<O> of type @i<T> is declared and explicitly specified
1951 as atomic, the implementation may introduce an additional copy on passing @i<O>
1952 to a subprogram with a parameter of type @i<T> that is normally passed by
1953 reference. A corresponding permission applies to volatile parameter passing.]}
1954 @end{ImplPerm}
1955
1956 @begin{ImplAdvice}
1957 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
1958 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0128-1]}
1959 @ChgAdded{Version=[2],Text=[A load or store of a volatile object whose size is
1960 a multiple of System.Storage_Unit and whose alignment is nonzero, should be
1961 implemented by accessing exactly the bits of the object and no
1962 others@Chg{Version=[5],New=[, except in
1963 the case of a volatile but nonatomic subcomponent of an atomic object],Old=[]}.]}
1964 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1965 Text=[A load or store of a volatile object whose size is
1966 a multiple of System.Storage_Unit and whose alignment is nonzero, should be
1967 implemented by accessing exactly the bits of the object and no others.]}]}
1968
1969 @begin{Reason}
1970 @ChgRef{Version=[2],Kind=[AddedNormal]}
1971 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0128-1]}
1972 @ChgAdded{Version=[2],Text=[Since any object can be a volatile object,
1973 including packed array components and bit-mapped record components, we
1974 require the above only when it is reasonable to assume that the machine
1975 can avoid accessing bits outside of the object.@Chg{Version=[5],New=[ The
1976 exception is needed so this advice doesn't conflict with other rules of
1977 this subclauase.],Old=[]}]}
1978 @end{Reason}
1979
1980 @begin{Ramification}
1981 @ChgRef{Version=[2],Kind=[AddedNormal]}
1982 @ChgAdded{Version=[2],Text=[This implies that the load or store of a
1983 volatile object that meets the above requirement should not be combined
1984 with that of any other object, nor should it access any bits not
1985 belonging to any other object. This means that the suitability of the
1986 implementation for memory-mapped I/O can be determined from its
1987 documentation, as any cases where the implementation does not follow
1988 @ImplAdviceTitle must be documented.]}
1989 @end{Ramification}
1990
1991 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
1992 @ChgAdded{Version=[2],Text=[A load or store of an atomic object should, where
1993 possible, be implemented by a single load or store instruction.]}
1994 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
1995 Text=[A load or store of an atomic object should be implemented by a single
1996 load or store instruction.]}]}
1997
1998 @end{ImplAdvice}
1999
2000 @begin{Notes}
2001
2002 An imported volatile or atomic constant behaves as a constant (i.e.
2003 read-only) with respect to other parts of the Ada program, but can
2004 still be modified by an @lquotes@;external source.@rquotes@;
2005
2006 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2007 @ChgAdded{Version=[4],Text=[Specifying the Pack aspect cannot override the
2008 effect of specifying an Atomic or Atomic_Components aspect.]}
2009
2010 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0128-1]}
2011 @ChgAdded{Version=[5],Text=[When mapping an Ada object to a memory-mapped
2012 hardware register, the Ada object should be declared atomic to ensure that the
2013 compiler will read and write exactly the bits of the register as specified in
2014 the source code and no others.]}
2015
2016 @begin{Discussion}
2017 @ChgRef{Version=[5],Kind=[AddedNormal]}
2018 @ChgAdded{Version=[5],Text=[This is especially important for a write-only
2019 hardware register, as in such a case a read-modify-write cycle will not work.
2020 The only time the language guarantees such a cycle will not happen is when
2021 writing an entire atomic object. If one wants to write individual components
2022 of a write-only hardware register (assuming the hardware supports that), those
2023 also need to be declared atomic.]}
2024 @end{Discussion}
2025
2026 @end{Notes}
2027
2028 @begin{Incompatible83}
2029 @Defn{incompatibilities with Ada 83}
2030 Pragma Atomic replaces Ada 83's pragma Shared.
2031 The name @lquotes@;Shared@rquotes@; was confusing,
2032 because the pragma was not used to mark variables as shared.
2033 @end{Incompatible83}
2034
2035 @begin{DiffWord95}
2036 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00259-01]}
2037 @ChgAdded{Version=[2],Text=[Added @ImplAdviceTitle to clarify the meaning
2038 of Atomic and Volatile in machine terms. The documentation that this
2039 advice applies will make the use of Ada implementations more predictable
2040 for low-level (such as device register) programming.]}
2041
2042 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00272-01]}
2043 @ChgAdded{Version=[2],Text=[Added wording to clarify that a slice of an
2044 object of an atomic type is not atomic, just like a component of an atomic
2045 type is not (necessarily) atomic.]}
2046 @end{Diffword95}
2047
2048 @begin{Incompatible2005}
2049 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0218-1]}
2050 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:>
2051 Plugged a hole involving volatile components of formal types when the formal
2052 type's component has a nonvolatile type. This was done by making certain
2053 actual types illegal for formal derived and formal array types; these types
2054 were allowed for Ada 95 and Ada 2005.]}
2055 @end{Incompatible2005}
2056
2057 @begin{Extend2005}
2058 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0009-1],ARef=[AI05-0229-1]}
2059 @ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}
2060 Aspects Independent and Independent_Components are new; they eliminate
2061 ambiguity about independent addressability.]}
2062
2063 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]}
2064 @ChgAdded{Version=[3],Text=[Aspects Atomic, Atomic_Components, Volatile,
2065 and Volatile_Components are
2066 new; @nt{pragma}s Atomic, Atomic_Components, Volatile, and
2067 Volatile_Components are now obsolescent.]}
2068 @end{Extend2005}
2069
2070 @begin{DiffWord2005}
2071 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0117-1],ARef=[AI05-0275-1]}
2072 @ChgAdded{Version=[3],Text=[Revised the definition of volatile to
2073 eliminate overspecification and simply focus on the root requirement (that
2074 all tasks see the same view of volatile objects). This is not an
2075 inconsistency; "memory" arguably includes on-chip caches so long as those are
2076 kept consistent. Moreover, it is difficult to imagine a program that could tell
2077 the difference.]}
2078
2079 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]}
2080 @ChgAdded{Version=[3],Text=[Added wording to take explicitly aliased
2081 parameters (see @RefSecNum{Subprogram Declarations}) into
2082 account when determining the legality of parameter passing of volatile and
2083 atomic objects.]}
2084 @end{DiffWord2005}
2085
2086 @begin{Inconsistent2012}
2087 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0128-1]}
2088 @ChgAdded{Version=[5],Text=[@Defn{inconsistencies with Ada 2012} Required
2089 that nonatomic components of a atomic object use a read-modify-write cycle, as
2090 well as clarifying that such a cycle is allowed for volatile objects that
2091 aren't exactly the size of a machine scalar. That can introduce a
2092 read-modify-write cycle where one was not used previously (for instance, if
2093 the components are exactly byte-sized on most machines); it is thought that
2094 this will more often fix bugs with access to hardware than it will cause them.
2095 If this is an issue, declaring the components themselves as atomic will
2096 restore the previous behavior.]}
2097 @end{Inconsistent2012}
2098
2099 @begin{Extend2012}
2100 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0282-1]}
2101 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2102 These aspects now can be specified for generic formal types.]}
2103 @end{Extend2012}
2104
2105 @begin{DiffWord2012}
2106 @ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0001-1]}
2107 @ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified that aliased objects
2108 are considered to be specified as independently addressable, and also
2109 eliminated an unnecessary rule.]}
2110 @end{DiffWord2012}
2111
2112
2113 @LabeledAddedSubclause{Version=[5],Name=[The Package System.Atomic_Operations]}
2114
2115 @begin{Intro}
2116 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2117 @ChgAdded{Version=[5],Text=[The language-defined package
2118 System.Atomic_Operations is the parent of a set of child
2119 units that provide facilities for manipulating objects of atomic types and for
2120 supporting lock-free synchronization. The subprograms of this subsystem are
2121 Intrinsic subprograms (see @RefSecNum{Conformance Rules}) in order to provide
2122 convenient access to machine operations that can provide these capabilities if
2123 they are available in the target environment.]}
2124 @end{Intro}
2125
2126 @begin{StaticSem}
2127
2128 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0234-1]}
2129 @ChgAdded{Version=[5],KeepNext=[T],Type=[Leading],Text=[The library package
2130 System.Atomic_Operations has the following declaration:]}
2131
2132 @begin{Example}
2133 @ChgRef{Version=[5],Kind=[AddedNormal]}
2134 @ChgAdded{Version=[5],Text=[@key{package} System.Atomic_Operations@ChildUnit{Parent=[System],Child=[Atomic_Operations]}
2135 @key{with} Pure, Nonblocking @key{is}
2136 @key{end} System.Atomic_Operations;]}
2137 @end{Example}
2138
2139 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2140 @ChgAdded{Version=[5],Text=[System.Atomic_Operations serves as the parent of
2141 other language-defined library units that manipulate atomic objects; its
2142 declaration is empty.]}
2143
2144 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2145 @ChgAdded{Version=[5],Text=[A call to a subprogram is said to be @i<lock-free>
2146 @Defn{lock-free} if the subprogram is guaranteed to return from the call while
2147 keeping the processor of the logical thread of control busy for the duration of
2148 the call.]}
2149
2150 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2151 @ChgAdded{Version=[5],Text=[In each child package, a function Is_Lock_Free(...)
2152 is provided to check whether the operations of the child package can all be
2153 provided lock-free for a given object. Is_Lock_Free returns True if operations
2154 defined in the child package are lock-free when applied to the object denoted by
2155 Item, and Is_Lock_Free returns False otherwise.]}
2156
2157 @end{StaticSem}
2158
2159 @begin{Extend2012}
2160 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0234-1]}
2161 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2162 This package is new.]}
2163 @end{Extend2012}
2164
2165
2166 @LabeledAddedSubclause{Version=[5],Name=[The Package System.Atomic_Operations.Exchange]}
2167
2168
2169 @begin{Intro}
2170 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2171 @ChgAdded{Version=[5],Type=[Leading],Text=[The language-defined generic package
2172 System.Atomic_Operations.Exchange provides the following operations:]}
2173
2174 @begin{Itemize}
2175
2176 @ChgRef{Version=[5],Kind=[AddedNormal]}
2177 @ChgAdded{Version=[5],Text=[To atomically compare the value of two
2178 atomic objects, and update the first atomic object with a desired value if
2179 both objects were found to be equal, or otherwise update the second object
2180 with the value of the first object.]}
2181
2182 @ChgRef{Version=[5],Kind=[AddedNormal]}
2183 @ChgAdded{Version=[5],Text=[To atomically update the value of an atomic
2184 object, and then return the value that the atomic object had just prior to
2185 the update.]}
2186
2187 @end{Itemize}
2188
2189 @end{Intro}
2190
2191 @begin{StaticSem}
2192
2193 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0234-1]}
2194 @ChgAdded{Version=[5],KeepNext=[T],Type=[Leading],Text=[The generic library
2195 package System.Atomic_Operations.Exchange has the following declaration:]}
2196
2197 @begin{Example}
2198 @ChgRef{Version=[5],Kind=[AddedNormal]}
2199 @ChgAdded{Version=[5],Text=[@key{generic}
2200 @key{type} Atomic_Type @key{is private with} Atomic;
2201 @key{package} System.Atomic_Operations.Exchange@ChildUnit{Parent=[System.Atomic_Operations],Child=[Exchange]}
2202 @key{with} Pure, Nonblocking @key{is}]}
2203
2204 @ChgRef{Version=[5],Kind=[AddedNormal]}
2205 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Exchange} (Item : @key{aliased in out} Atomic_Type;
2206 Value : Atomic_Type) @key{return} Atomic_Type
2207 @key{with} Convention => Intrinsic;]}
2208
2209 @ChgRef{Version=[5],Kind=[AddedNormal]}
2210 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Compare_And_Exchange} (Item : @key{aliased in out} Atomic_Type;
2211 Prior : @key{aliased in out} Atomic_Type;
2212 Desired : Atomic_Type) @key{return} Boolean
2213 @key{with} Convention => Intrinsic;]}
2214
2215 @ChgRef{Version=[5],Kind=[AddedNormal]}
2216 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Lock_Free} (Item : @key{aliased} Atomic_Type) @key{return} Boolean
2217 @key{with} Convention => Intrinsic;]}
2218
2219 @ChgRef{Version=[5],Kind=[AddedNormal]}
2220 @ChgAdded{Version=[5],Text=[@key{end} System.Atomic_Operations.Exchange;]}
2221 @end{Example}
2222
2223 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2224 @ChgAdded{Version=[5],Text=[Atomic_Exchange atomically assigns the value of
2225 Value to Item, and returns the previous value of Item.]}
2226
2227 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2228 @ChgAdded{Version=[5],Type=[Leading],Text=[Atomic_Compare_And_Exchange first
2229 evaluates the value of Prior.
2230 Atomic_Compare_And_Exchange then performs the following steps
2231 as part of a single indivisible operation:]}
2232
2233 @begin{Itemize}
2234
2235 @ChgRef{Version=[5],Kind=[AddedNormal]}
2236 @ChgAdded{Version=[5],Text=[evaluates the value of Item;]}
2237
2238 @ChgRef{Version=[5],Kind=[AddedNormal]}
2239 @ChgAdded{Version=[5],Text=[compares the value of Item with the value of Prior;]}
2240
2241 @ChgRef{Version=[5],Kind=[AddedNormal]}
2242 @ChgAdded{Version=[5],Text=[if equal, assigns Item the value of Desired;]}
2243
2244 @ChgRef{Version=[5],Kind=[AddedNormal]}
2245 @ChgAdded{Version=[5],Text=[otherwise, makes no change to the value of Item.]}
2246
2247 @end{Itemize}
2248
2249 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2250 @ChgAdded{Version=[5],Text=[After these steps, if the value of Item and Prior
2251 did not match, Prior is assigned the original value of Item, and the function
2252 returns False. Otherwise, Prior is unaffected and the function returns True.]}
2253
2254 @end{StaticSem}
2255
2256 @begin{Examples}
2257
2258 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI05-0234-1]}
2259 @ChgAdded{Version=[5],Type=[Leading],Text=[@i{Example of a spin
2260 lock using Atomic_Exchange:}]}
2261
2262 @begin{Example}
2263 @ChgRef{Version=[5],Kind=[AddedNormal]}
2264 @ChgAdded{Version=[5],Text=[@key{type} Atomic_Boolean @key{is new} Boolean @key{with} Atomic;
2265 @key{package} Exchange @key{is new}
2266 Atomic_Operations.Exchange (Atomic_Type => Atomic_Boolean);]}
2267
2268 @ChgRef{Version=[5],Kind=[AddedNormal]}
2269 @ChgAdded{Version=[5],Text=[Lock : @key{aliased} Atomic_Boolean := False;]}
2270
2271 @ChgRef{Version=[5],Kind=[AddedNormal]}
2272 @ChgAdded{Version=[5],Text=[...]}
2273
2274 @ChgRef{Version=[5],Kind=[AddedNormal]}
2275 @ChgAdded{Version=[5],Text=[@key{begin} -- @examcom{Some critical section, trying to get the lock:}]}
2276
2277 @ChgRef{Version=[5],Kind=[AddedNormal]}
2278 @ChgAdded{Version=[5],Text=[ -- @examcom{Obtain the lock}
2279 @key{while} Exchange.Atomic_Exchange (Item => Lock, Value => True) @key{loop}
2280 @key{null};
2281 @key{end loop};]}
2282
2283 @ChgRef{Version=[5],Kind=[AddedNormal]}
2284 @ChgAdded{Version=[5],Text=[ ... -- @examcom{Do stuff}]}
2285
2286 @ChgRef{Version=[5],Kind=[AddedNormal]}
2287 @ChgAdded{Version=[5],Text=[ Lock := False; -- @examcom{Release the lock}
2288 @key{end};]}
2289 @end{Example}
2290 @end{Examples}
2291
2292 @begin{Extend2012}
2293 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0234-1]}
2294 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2295 This package is new.]}
2296 @end{Extend2012}
2297
2298
2299 @LabeledAddedSubclause{Version=[5],Name=[The Package System.Atomic_Operations.Test_and_Set]}
2300
2301 @begin{Intro}
2302 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2303 @ChgAdded{Version=[5],Text=[The language-defined package
2304 System.Atomic_Operations.Test_And_Set provides an operation to atomically set
2305 and clear an atomic flag object.]}
2306 @end{Intro}
2307
2308 @begin{StaticSem}
2309
2310 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2311 @ChgAdded{Version=[5],KeepNext=[T],Type=[Leading],Text=[The library
2312 package System.Atomic_Operations.Test_And_Set has the following declaration:]}
2313
2314 @begin{Example}
2315 @ChgRef{Version=[5],Kind=[AddedNormal]}
2316 @ChgAdded{Version=[5],Text=[@key{package} System.Atomic_Operations.Test_And_Set@ChildUnit{Parent=[System.Atomic_Operations],Child=[Test_And_Set]}
2317 @key{with} Pure, Nonblocking @key{is}]}
2318
2319 @ChgRef{Version=[5],Kind=[AddedNormal]}
2320 @ChgAdded{Version=[5],Text=[ @key{type} @AdaTypeDefn{Test_And_Set_Flag} @key{is mod} @examcom<implementation-defined>
2321 @key{with} Atomic, Default_Value => 0, Size => @examcom<implementation-defined>;]}
2322
2323 @ChgRef{Version=[5],Kind=[AddedNormal]}
2324 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Test_And_Set}
2325 (Item : @key{aliased in out} Test_And_Set_Flag) @key{return} Boolean
2326 @key{with} Convention => Intrinsic;]}
2327
2328 @ChgRef{Version=[5],Kind=[AddedNormal]}
2329 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Atomic_Clear}
2330 (Item : @key{aliased in out} Test_And_Set_Flag)
2331 @key{with} Convention => Intrinsic;]}
2332
2333 @ChgRef{Version=[5],Kind=[AddedNormal]}
2334 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Lock_Free}
2335 (Item : @key{aliased} Test_And_Set_Flag) @key{return} Boolean
2336 @key{with} Convention => Intrinsic;]}
2337
2338 @ChgRef{Version=[5],Kind=[AddedNormal]}
2339 @ChgAdded{Version=[5],Text=[@key{end} System.Atomic_Operations.Test_And_Set;]}
2340 @end{Example}
2341
2342 @ChgImplDef{Version=[5],Kind=[AddedNormal],InitialVersion=[5],
2343 Text=[@Chg{Version=[5],New=[The modulus and size of Test_and_Set_Flag.],Old=[]}]}
2344
2345 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2346 @ChgAdded{Version=[5],Text=[Test_And_Set_Flag represents the state of an
2347 atomic flag object. An atomic flag object can either be considered to be set or
2348 cleared.]}
2349
2350 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2351 @ChgAdded{Version=[5],Text=[Atomic_Test_And_Set performs an atomic
2352 test-and-set operation on Item. Item is set to some implementation-defined
2353 nonzero value. The function returns True if the previous contents were nonzero,
2354 and otherwise returns False.]}
2355
2356 @ChgImplDef{Version=[5],Kind=[AddedNormal],InitialVersion=[5],
2357 Text=[@Chg{Version=[5],New=[The value used to represent the set value for
2358 Atomic_Test_and_Set.],Old=[]}]}
2359
2360 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2361 @ChgAdded{Version=[5],Text=[Atomic_Clear performs an atomic clear
2362 operation on Item. After the operation, Item contains 0. This call should be
2363 used in conjunction with Atomic_Test_And_Set.]}
2364
2365 @end{StaticSem}
2366
2367 @begin{Extend2012}
2368 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2369 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2370 This package is new.]}
2371 @end{Extend2012}
2372
2373
2374 @LabeledAddedSubclause{Version=[5],Name=[The Package System.Atomic_Operations.Integer_Arithmetic]}
2375
2376
2377 @begin{Intro}
2378 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1],ARef=[AI12-0364-1]}
2379 @ChgAdded{Version=[5],Text=[The language-defined generic package
2380 System.Atomic_Operations.Integer_Arithmetic provides operations to perform arithmetic
2381 atomically on objects of integer types.]}
2382 @end{Intro}
2383
2384 @begin{StaticSem}
2385
2386 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1],ARef=[AI12-0364-1]}
2387 @ChgAdded{Version=[5],KeepNext=[T],Type=[Leading],Text=[The generic library
2388 package System.Atomic_Operations.Integer_Arithmetic has the following declaration:]}
2389
2390 @begin{Example}
2391 @ChgRef{Version=[5],Kind=[AddedNormal]}
2392 @ChgAdded{Version=[5],Text=[@key{generic}
2393 @key{type} Atomic_Type @key{is range} <> @key{with} Atomic;
2394 @key{package} System.Atomic_Operations.Integer_Arithmetic@ChildUnit{Parent=[System.Atomic_Operations],Child=[Integer_Arithmetic]}
2395 @key{with} Pure, Nonblocking @key{is}]}
2396
2397 @ChgRef{Version=[5],Kind=[AddedNormal]}
2398 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Atomic_Add} (Item : @key{aliased in out} Atomic_Type;
2399 Value : Atomic_Type)
2400 @key{with} Convention => Intrinsic;]}
2401
2402 @ChgRef{Version=[5],Kind=[AddedNormal]}
2403 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Atomic_Subtract} (Item : @key{aliased in out} Atomic_Type;
2404 Value : Atomic_Type)
2405 @key{with} Convention => Intrinsic;]}
2406
2407 @ChgRef{Version=[5],Kind=[AddedNormal]}
2408 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Fetch_And_Add}
2409 (Item : @key{aliased in out} Atomic_Type;
2410 Value : Atomic_Type) @key{return} Atomic_Type
2411 @key{with} Convention => Intrinsic;]}
2412
2413 @ChgRef{Version=[5],Kind=[AddedNormal]}
2414 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Fetch_And_Subtract}
2415 (Item : @key{aliased in out} Atomic_Type;
2416 Value : Atomic_Type) @key{return} Atomic_Type
2417 @key{with} Convention => Intrinsic;]}
2418
2419 @ChgRef{Version=[5],Kind=[AddedNormal]}
2420 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Lock_Free} (Item : @key{aliased} Atomic_Type) @key{return} Boolean
2421 @key{with} Convention => Intrinsic;]}
2422
2423 @ChgRef{Version=[5],Kind=[AddedNormal]}
2424 @ChgAdded{Version=[5],Text=[@key{end} System.Atomic_Operations.Integer_Arithmetic;]}
2425 @end{Example}
2426
2427 @begin{DescribeCode}
2428
2429 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2430 @ChgAdded{Version=[5],Text=[The operations of this package are defined
2431 as follows:]}
2432
2433 @begin{Example}
2434 @ChgRef{Version=[5],Kind=[AddedNormal]}
2435 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Atomic_Add (Item : @key[aliased in out] Atomic_Type;
2436 Value : Atomic_Type)
2437 @key[with] Convention => Intrinsic;]}
2438 @end{Example}
2439
2440 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2441 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2442 @exam{Item := Item + Value;}]}
2443
2444 @begin{Example}
2445 @ChgRef{Version=[5],Kind=[AddedNormal]}
2446 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Atomic_Subtract (Item : @key[aliased in out] Atomic_Type;
2447 Value : Atomic_Type)
2448 @key[with] Convention => Intrinsic;]}
2449 @end{Example}
2450
2451 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2452 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2453 @exam{Item := Item - Value;}]}
2454
2455 @begin{Example}
2456 @ChgRef{Version=[5],Kind=[AddedNormal]}
2457 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Atomic_Fetch_And_Add
2458 (Item : @key[aliased in out] Atomic_Type;
2459 Value : Atomic_Type) @key[return] Atomic_Type
2460 @key[with] Convention => Intrinsic;]}
2461 @end{Example}
2462
2463 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2464 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2465 @exam{Tmp := Item; Item := Item + Value; @key[return] Tmp;}]}
2466
2467 @begin{Example}
2468 @ChgRef{Version=[5],Kind=[AddedNormal]}
2469 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Atomic_Fetch_And_Subtract
2470 (Item : @key[aliased in out] Atomic_Type;
2471 Value : Atomic_Type) @key[return] Atomic_Type
2472 @key[with] Convention => Intrinsic;]}
2473 @end{Example}
2474
2475 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2476 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2477 @exam{Tmp := Item; Item := Item - Value; @key[return] Tmp;}]}
2478
2479 @end{DescribeCode}
2480 @end{StaticSem}
2481
2482 @begin{Extend2012}
2483 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0321-1]}
2484 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2485 This package is new.]}
2486 @end{Extend2012}
2487
2488
2489 @LabeledAddedSubclause{Version=[5],Name=[The Package System.Atomic_Operations.Modular_Arithmetic]}
2490
2491
2492 @begin{Intro}
2493 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2494 @ChgAdded{Version=[5],Text=[The language-defined generic package
2495 System.Atomic_Operations.Modular_Arithmetic provides operations to perform arithmetic
2496 atomically on objects of modular types.]}
2497 @end{Intro}
2498
2499 @begin{StaticSem}
2500
2501 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2502 @ChgAdded{Version=[5],KeepNext=[T],Type=[Leading],Text=[The generic library
2503 package System.Atomic_Operations.Modular_Arithmetic has the following declaration:]}
2504
2505 @begin{Example}
2506 @ChgRef{Version=[5],Kind=[AddedNormal]}
2507 @ChgAdded{Version=[5],Text=[@key{generic}
2508 @key{type} Atomic_Type @key{is mod} <> @key{with} Atomic;
2509 @key{package} System.Atomic_Operations.Modular_Arithmetic@ChildUnit{Parent=[System.Atomic_Operations],Child=[Modular_Arithmetic]}
2510 @key{with} Pure, Nonblocking @key{is}]}
2511
2512 @ChgRef{Version=[5],Kind=[AddedNormal]}
2513 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Atomic_Add} (Item : @key{aliased in out} Atomic_Type;
2514 Value : Atomic_Type)
2515 @key{with} Convention => Intrinsic;]}
2516
2517 @ChgRef{Version=[5],Kind=[AddedNormal]}
2518 @ChgAdded{Version=[5],Text=[ @key{procedure} @AdaSubDefn{Atomic_Subtract} (Item : @key{aliased in out} Atomic_Type;
2519 Value : Atomic_Type)
2520 @key{with} Convention => Intrinsic;]}
2521
2522 @ChgRef{Version=[5],Kind=[AddedNormal]}
2523 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Fetch_And_Add}
2524 (Item : @key{aliased in out} Atomic_Type;
2525 Value : Atomic_Type) @key{return} Atomic_Type
2526 @key{with} Convention => Intrinsic;]}
2527
2528 @ChgRef{Version=[5],Kind=[AddedNormal]}
2529 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Atomic_Fetch_And_Subtract}
2530 (Item : @key{aliased in out} Atomic_Type;
2531 Value : Atomic_Type) @key{return} Atomic_Type
2532 @key{with} Convention => Intrinsic;]}
2533
2534 @ChgRef{Version=[5],Kind=[AddedNormal]}
2535 @ChgAdded{Version=[5],Text=[ @key{function} @AdaSubDefn{Is_Lock_Free} (Item : @key{aliased} Atomic_Type) @key{return} Boolean
2536 @key{with} Convention => Intrinsic;]}
2537
2538 @ChgRef{Version=[5],Kind=[AddedNormal]}
2539 @ChgAdded{Version=[5],Text=[@key{end} System.Atomic_Operations.Modular_Arithmetic;]}
2540 @end{Example}
2541
2542 @begin{DescribeCode}
2543
2544 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2545 @ChgAdded{Version=[5],Text=[The operations of this package are defined
2546 as follows:]}
2547
2548 @begin{Example}
2549 @ChgRef{Version=[5],Kind=[AddedNormal]}
2550 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Atomic_Add (Item : @key[aliased in out] Atomic_Type;
2551 Value : Atomic_Type)
2552 @key[with] Convention => Intrinsic;]}
2553 @end{Example}
2554
2555 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2556 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2557 @exam{Item := Item + Value;}]}
2558
2559 @begin{Example}
2560 @ChgRef{Version=[5],Kind=[AddedNormal]}
2561 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{procedure} Atomic_Subtract (Item : @key[aliased in out] Atomic_Type;
2562 Value : Atomic_Type)
2563 @key[with] Convention => Intrinsic;]}
2564 @end{Example}
2565
2566 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2567 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2568 @exam{Item := Item - Value;}]}
2569
2570 @begin{Example}
2571 @ChgRef{Version=[5],Kind=[AddedNormal]}
2572 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Atomic_Fetch_And_Add
2573 (Item : @key[aliased in out] Atomic_Type;
2574 Value : Atomic_Type) @key[return] Atomic_Type
2575 @key[with] Convention => Intrinsic;]}
2576 @end{Example}
2577
2578 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2579 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2580 @exam{Tmp := Item; Item := Item + Value; @key[return] Tmp;}]}
2581
2582 @begin{Example}
2583 @ChgRef{Version=[5],Kind=[AddedNormal]}
2584 @ChgAdded{Version=[5],KeepNext=[T],Text=[@key{function} Atomic_Fetch_And_Subtract
2585 (Item : @key[aliased in out] Atomic_Type;
2586 Value : Atomic_Type) @key[return] Atomic_Type
2587 @key[with] Convention => Intrinsic;]}
2588 @end{Example}
2589
2590 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2591 @ChgAdded{Version=[5],Type=[Trailing],Text=[Atomically performs:
2592 @exam{Tmp := Item; Item := Item - Value; @key[return] Tmp;}]}
2593
2594 @end{DescribeCode}
2595 @end{StaticSem}
2596
2597 @begin{Extend2012}
2598 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0364-1]}
2599 @ChgAdded{Version=[5],Text=[@Defn{extensions to Ada 2012}
2600 This package is new.]}
2601 @end{Extend2012}
2602
2603
2604 @LabeledRevisedClause{Version=[2],New=[Task Information],
2605 Old=[Task Identification and Attributes]}
2606
2607 @begin{Intro}
2608 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00266-02]}
2609 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2610 @Redundant[This @Chg{Version=[3],New=[subclause],Old=[clause]}
2611 describes operations and attributes that can be
2612 used to obtain the identity of a task. In addition,
2613 a package that associates user-defined information with a task is
2614 defined.@Chg{Version=[2],New=[ Finally, a package that associates
2615 termination procedures with a task or set of tasks is defined.],Old=[]}]
2616 @end{Intro}
2617
2618 @begin{DiffWord95}
2619 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
2620 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]}
2621 @ChgAdded{Version=[2],Text=[The title and text here were updated to reflect
2622 the addition of task termination procedures to this @Chg{Version=[3],New=[subclause],Old=[clause]}.]}
2623 @end{DiffWord95}
2624
2625 @LabeledSubClause{The Package Task_Identification}
2626
2627 @begin{StaticSem}
2628 @Leading@Keepnext@;The following language-defined library package exists:
2629 @begin{example}
2630 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
2631 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
2632 @key[package] Ada.Task_Identification@Chg{Version=[5],New=[],Old=[ @key[is]]}@ChildUnit{Parent=[Ada],Child=[Task_Identification]}@Chg{Version=[2],New=[
2633 @Chg{Version=[5],New=[@key[with]],Old=[@key[pragma]]} Preelaborate@Chg{Version=[5],New=[, Nonblocking @key[is]],Old=[(Task_Identification);]}],Old=[]}
2634 @key[type] @AdaTypeDefn{Task_Id} @key[is] @key{private};@Chg{Version=[2],New=[
2635 @key[pragma] Preelaborable_Initialization (Task_Id);],Old=[]}
2636 @AdaSubDefn{Null_Task_Id} : @key{constant} Task_Id;
2637 @key{function} "=" (Left, Right : Task_Id) @key{return} Boolean;
2638
2639 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0070],ARef=[AI95-00101-01]}
2640 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0189-1]}
2641 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
2642 @key{function} @AdaSubDefn{Image} (T : Task_Id) @key{return} String;
2643 @key[function] @AdaSubDefn{Current_Task} @key[return] Task_Id;@Chg{Version=[3],New=[
2644 @key[function] @AdaSubDefn{Environment_Task} @key[return] Task_Id;],Old=[]}
2645 @Key[procedure] @AdaSubDefn{Abort_Task} (T : @key[in] @Chg{New=[],Old=[@key[out] ]}Task_Id)@Chg{Version=[5],New=[
2646 @key[with] Nonblocking => False],Old=[]};
2647
2648 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0189-1]}
2649 @key[function] @AdaSubDefn{Is_Terminated} (T : Task_Id) @key{return} Boolean;
2650 @key[function] @AdaSubDefn{Is_Callable} (T : Task_Id) @key{return} Boolean;@Chg{Version=[3],New=[
2651 @key[function] @AdaSubDefn{Activation_Is_Complete} (T : Task_Id) @key{return} Boolean;],Old=[]}
2652 @key[private]
2653 ... -- @RI{not specified by the language}
2654 @key[end] Ada.Task_Identification;
2655 @end{example}
2656 @end{StaticSem}
2657
2658 @begin{RunTime}
2659
2660 A value of the type Task_Id identifies an existent task. The constant
2661 Null_Task_Id does not identify any task. Each object of the type Task_Id
2662 is default initialized to the value of Null_Task_Id.
2663
2664 The function "=" returns True if and only if Left and Right identify the same
2665 task or both have the value Null_Task_Id.
2666
2667 The function Image returns an implementation-defined string that identifies
2668 T. If T equals Null_Task_Id, Image returns an empty string.
2669 @ImplDef{The result of the Task_Identification.Image attribute.}
2670
2671 The function Current_Task returns a value that identifies the calling task.
2672
2673 @begin{Ramification}
2674 @ChgRef{Version=[5],Kind=[Added],ARef=[AI12-0005-1]}
2675 @ChgAdded{Version=[5],Text=[The logical threads of control associated with the
2676 execution of a given parallel construct all execute as part of the execution
2677 of one task (see @RefSec{Tasks and Synchronization}). Thus, the result
2678 returned by a call to Task_Identification.Current_Task is independent of
2679 whether the call takes place during the execution of a parallel construct.]}
2680 @end{Ramification}
2681
2682 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0189-1]}
2683 @ChgAdded{Version=[3],Text=[The function Environment_Task returns a value that
2684 identifies the environment task.]}
2685
2686 The effect of Abort_Task is the same as the @nt{abort_statement} for the
2687 task identified by T. @Redundant[In addition, if T identifies the
2688 environment task, the entire partition is aborted, See @RefSecNum{Partitions}.]
2689
2690 The functions Is_Terminated and Is_Callable return the value of the
2691 corresponding attribute of the task identified by T.
2692 @begin{Ramification}
2693 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0115],ARef=[AI95-00206-01]}
2694 @ChgAdded{Version=[1],Text=[These routines can be called with an argument
2695 identifying the environment task. Is_Terminated will always be False for such a
2696 call, but Is_Callable (usually True) could be False if the environment task is
2697 waiting for the termination of dependent tasks. Thus, a dependent task can use
2698 Is_Callable to determine if the main subprogram has completed.]}
2699 @end{Ramification}
2700
2701 @ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0189-1]}
2702 @ChgAdded{Version=[3],Text=[The function Activation_Is_Complete returns True if the
2703 task identified by T has completed its activation (whether successfully or not).
2704 It returns False otherwise. If T identifies the environment task,
2705 Activation_Is_Complete returns True after the elaboration of the
2706 @nt{library_item}s of the partition has completed.]}
2707
2708 @Leading@;For @PrefixType{a @nt<prefix> T that is of a task type
2709 @Redundant[(after any implicit dereference)]},
2710 the following attribute is defined:
2711 @begin{Description}
2712
2713 @Attribute{Prefix=<T>, AttrName=<Identity>,
2714 Text=[Yields a value of the type Task_Id that identifies
2715 the task denoted by T.]}
2716
2717 @end{Description}
2718 @EndPrefixType{}
2719
2720 @Leading@;For @PrefixType{a @nt<prefix> E that denotes an
2721 @nt<entry_declaration>},
2722 the following attribute is defined:
2723 @begin{Description}
2724 @ChgAttribute{Version=[3],Kind=[Revised],ChginAnnex=[T],
2725 Leading=<F>, Prefix=<E>, AttrName=<Caller>, ARef=[AI05-0262-1],
2726 InitialVersion=[0], Text=[Yields a value of the type Task_Id that
2727 identifies the task whose call is now being serviced. Use of this
2728 attribute is allowed only inside an
2729 @Chg{Version=[3],New=[],Old=[@nt{entry_body}
2730 or ]}@nt{accept_statement}@Chg{Version=[3],New=[,
2731 or @nt{entry_body} after the
2732 @nt{entry_barrier}, ],Old=[]}corresponding
2733 to the @nt{entry_declaration} denoted by E.]}
2734 @end{Description}
2735 @EndPrefixType{}
2736
2737 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0231-1]}
2738 Program_Error is raised if a value of Null_Task_Id is passed
2739 as a parameter to Abort_Task,
2740 @Chg{Version=[5],New=[Activation_Is_Complete, ],Old=[]}Is_Terminated,
2741 and Is_Callable.
2742
2743 @ChgRef{Version=[5],Kind=[Deleted],ARef=[AI12-0241-1]}
2744 @ChgDeleted{Version=[5],Text=[@PDefn2{Term=[potentially blocking operation],Sec=(Abort_Task)}
2745 @PDefn2{Term=[blocking, potentially],Sec=(Abort_Task)}
2746 Abort_Task is a potentially blocking operation
2747 (see @RefSecNum{Protected Subprograms and Protected Actions}).]}
2748 @end{RunTime}
2749
2750 @begin{Bounded}
2751 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}
2752 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0004-1]}
2753 @PDefn2{Term=(bounded error),Sec=(cause)}
2754 It is a bounded error to call the Current_Task function from
2755 an @Chg{Version=[3],New=[@nt{entry_body}],Old=[entry body]}@Chg{Version=[2],New=[,],Old=[ or an]}
2756 interrupt handler@Chg{Version=[2],New=[, or finalization of a task attribute],Old=[]}.
2757 Program_Error is raised, or an implementation-defined value of the type
2758 Task_Id is returned.@Defn2{Term=[Program_Error],Sec=(raised by detection of a bounded error)}
2759 @ChgImplDef{Version=[2],Kind=[Revised],InitialVersion=[0],
2760 Text=[The value of Current_Task when in
2761 a protected entry@Chg{Version=[2],New=[,],Old=[ or]} interrupt handler@Chg{Version=[2],
2762 New=[, or finalization of a task attribute],Old=[]}.]}
2763 @begin{ImplNote}
2764 This value could be Null_Task_Id, or the ID of some user task, or that of
2765 an internal task created by the implementation.
2766 @end{ImplNote}
2767 @begin{Ramification}
2768 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}@Comment{This really should reference AI05-0004, but we don't have that yet. And that hasn't been approved, either}
2769 @ChgAdded{Version=[2],Text=[An entry barrier is syntactically part of an
2770 @nt{entry_body}, so a call to Current_Task from an entry barrier is also
2771 covered by this rule.]}
2772 @end{Ramification}
2773
2774 @end{Bounded}
2775
2776 @begin{Erron}
2777 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2778 If a value of Task_Id is passed as a parameter to any of the operations
2779 declared in this package (or any language-defined child of this
2780 package), and the corresponding task object no longer exists,
2781 the execution of the program is erroneous.
2782 @end{Erron}
2783
2784 @begin{DocReq}
2785
2786 The implementation shall document the effect of calling Current_Task
2787 from an entry body or interrupt handler.
2788 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
2789 Text=[@ChgDeleted{Version=[2],
2790 Text=[The effect of calling Current_Task from an
2791 entry body or interrupt handler.]}]}
2792 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
2793 Text=[The effect of calling Current_Task from an
2794 entry body or interrupt handler.]}]}
2795 @end{DocReq}
2796
2797 @begin{Notes}
2798
2799 This package is intended for use in writing user-defined task scheduling
2800 packages and constructing server tasks. Current_Task can be used in
2801 conjunction with other operations requiring a task as an argument such
2802 as Set_Priority (see @RefSecNum{Dynamic Priorities}).
2803
2804 The function Current_Task and the attribute Caller can return a
2805 Task_Id value that identifies the environment task.
2806
2807 @end{Notes}
2808
2809 @begin{Extend95}
2810 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
2811 @ChgAdded{Version=[2],Text=[Task_Identification is now preelaborated,
2812 so it can be used in preelaborated units.]}
2813 @end{Extend95}
2814
2815 @begin{DiffWord95}
2816 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0070],ARef=[AI95-00101-01]}
2817 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the mode of the
2818 parameter to Abort_Task to @key{in}.]}
2819
2820 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
2821 @ChgAdded{Version=[2],Text=[Corrected the wording to include finalization
2822 of a task attribute in the bounded error case; we don't want to specify
2823 which task does these operations.]}
2824 @end{Diffword95}
2825
2826 @begin{Incompatible2005}
2827 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0189-1]}
2828 @ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}
2829 Functions Environment_Task and Activation_Is_Complete are added to
2830 Task_Identification. If Task_Identification is referenced in a @nt{use_clause}, and an
2831 entity @i<E> with a @nt{defining_identifier} of Environment_Task or
2832 Activation_Is_Complete is defined in a package that is also referenced in a
2833 @nt{use_clause}, the entity @i<E> may no longer be use-visible, resulting in
2834 errors. This should be rare and is easily fixed if it does occur.]}
2835 @end{Incompatible2005}
2836
2837 @begin{DiffWord2012}
2838 @ChgRef{Version=[5],Kind=[AddedNormal],ARef=[AI12-0231-1]}
2839 @ChgAdded{Version=[5],Text=[@b<Correction:> Defined what happens if
2840 Null_Task_Id is passed to Activation_Is_Complete.]}
2841 @end{DiffWord2012}
2842
2843
2844 @LabeledSubClause{The Package Task_Attributes}
2845
2846 @begin{StaticSem}
2847 @Leading@Keepnext@;The following language-defined generic library package exists:
2848 @begin{example}
2849 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
2850 @key{with} Ada.Task_Identification; @key{use} Ada.Task_Identification;
2851 @key{generic}
2852 @key{type} Attribute @key{is} @key{private};
2853 Initial_Value : @key[in] Attribute;
2854 @key{package} Ada.Task_Attributes@Chg{Version=[5],New=[
2855 @key{with} Nonblocking],Old=[]} @key{is}@ChildUnit{Parent=[Ada],Child=[Task_Attributes]}
2856
2857 @key{type} @AdaTypeDefn{Attribute_Handle} @key{is} @key{access} @key{all} Attribute;
2858
2859 @key{function} @AdaSubDefn{Value}(T : Task_Id := Current_Task)
2860 @key{return} Attribute;
2861
2862 @key{function} @AdaSubDefn{Reference}(T : Task_Id := Current_Task)
2863 @key{return} Attribute_Handle;
2864
2865 @key{procedure} @AdaSubDefn{Set_Value}(Val : @key[in] Attribute;
2866 T : @key[in] Task_Id := Current_Task);
2867 @key{procedure} @AdaSubDefn{Reinitialize}(T : @key[in] Task_Id := Current_Task);
2868
2869 @key{end} Ada.Task_Attributes;
2870 @end{example}
2871
2872 @end{StaticSem}
2873
2874 @begin{RunTime}
2875
2876 When an instance of Task_Attributes is elaborated in
2877 a given active partition, an object of the
2878 actual type corresponding to the formal type Attribute
2879 is implicitly created for each task (of that partition)
2880 that exists and is not yet terminated.
2881 This object acts as a user-defined attribute of the task.
2882 A task created previously
2883 in the partition and not yet terminated has this attribute
2884 from that point on. Each task subsequently created in the partition
2885 will have this attribute when created. In all these cases, the initial value
2886 of the given attribute is Initial_Value.
2887
2888 The Value operation returns the value of the corresponding attribute of T.
2889
2890 The Reference operation returns an access value that designates the
2891 corresponding attribute of T.
2892
2893 The Set_Value operation performs any finalization on the old value of the
2894 attribute of T and assigns Val to that attribute
2895 (see @RefSecNum{Assignment Statements} and
2896 @RefSecNum{Assignment and Finalization}).
2897
2898 The effect of the Reinitialize operation is the same as Set_Value where
2899 the Val parameter is replaced with Initial_Value.
2900 @begin{ImplNote}
2901 In most cases, the attribute memory can be reclaimed at this point.
2902 @end{ImplNote}
2903
2904 For all the operations declared in this package, Tasking_Error is raised
2905 if the task identified by T is terminated.
2906 Program_Error is raised if the value of T is Null_Task_Id.
2907
2908 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00237-01]}
2909 @ChgAdded{Version=[2],Text=[After a task has terminated, all of its attributes
2910 are finalized, unless they have been finalized earlier. When the master of an
2911 instantiation of Ada.Task_Attributes is finalized, the corresponding attribute
2912 of each task is finalized, unless it has been finalized earlier.]}
2913 @begin{Reason}
2914 @ChgRef{Version=[2],Kind=[AddedNormal]}
2915 @ChgAdded{Version=[2],Text=[This is necessary so that a task attribute does
2916 not outlive its type. For instance, that's possible if the instantiation is
2917 nested, and the attribute is on a library-level task.]}
2918 @end{Reason}
2919 @begin{Ramification}
2920 @ChgRef{Version=[2],Kind=[AddedNormal]}
2921 @ChgAdded{Version=[2],Text=[The task owning an attribute cannot, in general,
2922 finalize that attribute. That's because the attributes are finalized @i<after>
2923 the task is terminated; moreover, a task may have attributes as soon as it is
2924 created; the task may never even have been activated.]}
2925 @end{Ramification}
2926 @end{RunTime}
2927
2928 @begin{Bounded}
2929 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0071],ARef=[AI95-00165-01]}
2930 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(bounded error),Sec=(cause)}
2931 If the package Ada.Task_Attributes is instantiated with a controlled type and
2932 the controlled type has user-defined Adjust or Finalize operations that in
2933 turn access task attributes by any of the above operations, then a call of
2934 Set_Value of the instantiated package constitutes a bounded error. The call
2935 may perform as expected or may result in forever blocking the calling task and
2936 subsequently some or all tasks of the partition.]}
2937 @end{Bounded}
2938
2939 @begin{Erron}
2940 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2941 It is erroneous to dereference the access value returned by a given
2942 call on Reference after a subsequent call on Reinitialize for
2943 the same task attribute, or after the associated task terminates.
2944 @begin{Reason}
2945 This allows the storage to be reclaimed for the object
2946 associated with an attribute upon Reinitialize or task termination.
2947 @end{Reason}
2948
2949 @PDefn2{Term=(erroneous execution),Sec=(cause)}
2950 If a value of Task_Id is passed as a parameter to any of the operations
2951 declared in this package and the corresponding task object no longer exists,
2952 the execution of the program is erroneous.
2953
2954 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0071],ARef=[AI95-00165-01]}
2955 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00237-01]}
2956 @ChgAdded{Version=[1],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}
2957 @Chg{Version=[2],New=[An access],Old=[Accesses]} to @Chg{Version=[2],New=[a ],Old=[]}task
2958 @Chg{Version=[2],New=[attribute],Old=[attributes]} via a value of type
2959 Attribute_Handle @Chg{Version=[2],New=[is],Old=[are]}
2960 erroneous if executed concurrently with @Chg{Version=[2],New=[another such access],
2961 Old=[each other]} or @Chg{Version=[2],New=[a call],Old=[with calls]} of any of the
2962 operations declared in package Task_Attributes.@Chg{Version=[2],New=[ An access
2963 to a task attribute is erroneous if executed
2964 concurrently with or after the finalization of the task attribute.],Old=[]}]}
2965 @begin{Reason}
2966 @ChgRef{Version=[1],Kind=[Added]}
2967 @ChgAdded{Version=[1],Text=[There is no requirement of atomicity on accesses
2968 via a value of type Attribute_Handle.]}
2969 @end{Reason}
2970 @begin{Ramification}
2971 @ChgRef{Version=[2],Kind=[Added]}
2972 @ChgAdded{Version=[2],Text=[A task attribute can only be accessed after
2973 finalization through a value of type Attribute_Handle. Operations in
2974 package Task_Attributes cannot be used to access a task attribute after
2975 finalization, because either the master of the instance has been or is in the
2976 process of being left (in which case the instance is out of scope and thus
2977 cannot be called), or the associated task is already terminated (in which
2978 case Tasking_Error is raised for any attempt to call a task attribute
2979 operation).]}
2980 @end{Ramification}
2981 @end{Erron}
2982
2983 @begin{ImplReq}
2984 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0071],ARef=[AI95-00165-01]}
2985 @Chg{New=[For a given attribute of a given task, the],Old=[The]} implementation
2986 shall perform @Chg{New=[the operations declared in this package],
2987 Old=[each of the above operations for a given attribute of a given task]}
2988 atomically with respect to any @Chg{New=[of these operations of],
2989 Old=[other of the above operations for]} the same attribute of the same task.
2990 @Chg{New=[The granularity of any locking mechanism necessary to achieve such
2991 atomicity is implementation defined.],Old=[]}
2992 @ChgImplDef{Version=[1],Kind=[Added],Text=[@Chg{New=[Granularity of
2993 locking for Task_Attributes.],Old=[]}]}
2994
2995 @begin{Ramification}
2996 Hence, other than by dereferencing an access value returned by
2997 Reference, an attribute of a given task can be safely read and updated
2998 concurrently by multiple tasks.
2999 @end{Ramification}
3000
3001 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00237-01]}
3002 @Chg{Version=[2],New=[After],Old=[When a]} task
3003 @Chg{Version=[2],New=[attributes are finalized],Old=[terminates]},
3004 the implementation shall @Chg{Version=[2],New=[],Old=[finalize
3005 all attributes of the task, and ]}reclaim any
3006 @Chg{Version=[2],New=[],Old=[other ]}storage associated with the attributes.
3007 @end{ImplReq}
3008
3009 @begin{DocReq}
3010
3011 The implementation shall document the limit on the number of attributes
3012 per task, if any, and the limit on the total storage for attribute values
3013 per task, if such a limit exists.
3014
3015 In addition, if these limits can be configured, the implementation shall
3016 document how to configure them.
3017 @ChgImplDef{Version=[2],Kind=[Deleted],InitialVersion=[0],
3018 Text=[@ChgDeleted{Version=[2],
3019 Text=[@Chg{New=[Limits on the number and size of task attributes, and how to configure them.],
3020 Old=[Implementation-defined aspects of Task_Attributes.]}]}]}
3021 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3022 Text=[For package Task_Attributes, limits on the number and size of task
3023 attributes, and how to configure any limits.]}]}
3024 @end{DocReq}
3025
3026 @begin{Metrics}
3027
3028 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
3029 The implementation shall document the following metrics: A task calling the
3030 following subprograms shall execute @Chg{Version=[2],New=[at],Old=[in]} a
3031 sufficiently high priority as to not
3032 be preempted during the measurement period. This period shall start just
3033 before issuing the call and end just after the call completes. If the
3034 attributes of task T are accessed by the measurement tests, no other task
3035 shall access attributes of that task during the measurement period.
3036 For all measurements described here, the Attribute type shall be a scalar
3037 @Chg{Version=[2],New=[type ],Old=[]}whose size is equal to the size of the
3038 predefined @Chg{Version=[2],New=[type Integer],Old=[integer size]}.
3039 For each measurement, two cases shall be documented: one
3040 where the accessed attributes are of the calling task @Redundant[(that is,
3041 the default value for the T parameter is used)], and the other, where T
3042 identifies another, nonterminated, task.
3043
3044 @Leading@;The following calls (to subprograms in the Task_Attributes package)
3045 shall be measured:
3046 @begin{Itemize}
3047 a call to Value, where the return value is Initial_Value;
3048
3049 a call to Value, where the return value is not equal to Initial_Value;
3050
3051 a call to Reference, where the return value designates a value equal to
3052 Initial_Value;
3053
3054 a call to Reference, where the return value designates a value not equal
3055 to Initial_Value;
3056
3057 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
3058 a call to Set_Value where the Val parameter is not equal to Initial_Value
3059 and the old attribute value is equal to Initial_Value@Chg{Version=[2],New=[;],Old=[.]}
3060
3061 a call to Set_Value where the Val parameter is not equal to Initial_Value
3062 and the old attribute value is not equal to Initial_Value.
3063
3064 @end{Itemize}
3065 @ChgDocReq{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3066 Text=[The metrics for the Task_Attributes package.]}]}
3067 @end{Metrics}
3068
3069 @begin{ImplPerm}
3070
3071 An implementation need not actually create the object corresponding
3072 to a task attribute
3073 until its value is set to something other than that of Initial_Value,
3074 or until Reference is called for the task attribute.
3075 Similarly, when the value of the attribute is
3076 to be reinitialized to that of Initial_Value,
3077 the object may instead be finalized and its storage reclaimed, to
3078 be recreated when needed later.
3079 While the object does not exist, the function Value may
3080 simply return Initial_Value, rather than implicitly creating the object.
3081 @begin{Discussion}
3082 The effect of this permission can only be observed if the assignment
3083 operation for the corresponding type has side effects.
3084 @end{Discussion}
3085 @begin{ImplNote}
3086 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3087 This permission means that even though every task has every
3088 attribute, storage need only be allocated for those attributes
3089 @Chg{Version=[2],New=[for which function Reference has been invoked],Old=[that
3090 have been Reference'd]} or set to a value other than that
3091 of Initial_Value.
3092 @end{ImplNote}
3093
3094 An implementation is allowed to place restrictions on the maximum number of
3095 attributes a task may have, the maximum size of each attribute, and the
3096 total storage size allocated for all the attributes of a task.
3097
3098 @end{ImplPerm}
3099
3100 @begin{ImplAdvice}
3101
3102 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
3103 Some implementations are targeted to domains in which memory use at run
3104 time must be completely deterministic. For such implementations, it is
3105 recommended that the storage for task attributes will be pre-allocated
3106 statically and not from the heap. This can be accomplished by either
3107 placing restrictions on the number and the size of the @Chg{Version=[2],
3108 New=[],Old=[task's ]}attributes@Chg{Version=[2],New=[ of a task],Old=[]},
3109 or by using the pre-allocated storage for the first N attribute objects,
3110 and the heap for the others. In the latter case, N should be documented.
3111
3112 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3113 Text=[If the target domain requires deterministic memory use at run
3114 time, storage for task attributes should be pre-allocated
3115 statically and the number of attributes pre-allocated should be documented.]}]}
3116
3117 @begin{Discussion}
3118 @ChgRef{Version=[2],Kind=[AddedNormal]}
3119 @ChgAdded{Version=[2],Text=[We don't mention @lquotes@;restrictions on the
3120 size and number@rquotes (that is, limits) in the text for the
3121 Annex, because it is covered by the @DocReqName above, and we try not to
3122 repeat requirements in the Annex (they're enough work to meet without
3123 having to do things twice).]}
3124 @end{Discussion}
3125 @end{ImplAdvice}
3126
3127 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00237-01]}
3128 @ChgAdded{Version=[2],Text=[Finalization of task attributes and reclamation of
3129 associated storage should be performed as soon as possible after task
3130 termination.]}
3131 @ChgImplAdvice{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3132 Text=[Finalization of task attributes and reclamation of
3133 associated storage should be performed as soon as possible after task
3134 termination.]}]}
3135 @begin{Reason}
3136 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
3137 @ChgAdded{Version=[2],Text=[This is necessary because the normative wording
3138 only says that attributes are finalized @lquotes@;after@rquotes@;
3139 task termination. Without this advice, waiting until the instance is
3140 finalized would meet the requirements (it is after termination, but may be
3141 a very long time after termination). We can't say anything more specific
3142 than this, as we do not want to require the overhead of an interaction with
3143 the tasking system to be done at a specific point.]}
3144 @end{Reason}
3145 @begin{Notes}
3146
3147 An attribute always exists (after instantiation), and has the initial value.
3148 It need not occupy memory until the first operation that potentially
3149 changes the attribute value. The same holds true after Reinitialize.
3150
3151 The result of the Reference function should be used with care; it is always
3152 safe to use that result in the task body whose attribute is being
3153 accessed. However, when the result is being used by another task, the
3154 programmer must make sure that the task whose attribute is being accessed
3155 is not yet terminated. Failing to do so could make the program execution
3156 erroneous.
3157
3158 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00434-01]}
3159 @ChgDeleted{Version=[2],Text=[As specified in
3160 @RefSecNum{The Package Task_Identification}, if the parameter T (in a call
3161 on a subprogram of an instance of this package) identifies a nonexistent
3162 task, the execution of the program is erroneous.]}
3163 @end{Notes}
3164
3165 @begin{DiffWord95}
3166 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0071],ARef=[AI95-00165-01]}
3167 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that use of task
3168 attribute operations from within a task attribute operation (by an Adjust
3169 or Finalize call) is a bounded error, and that concurrent use of attribute
3170 handles is erroneous.]}
3171
3172 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00237-01]}
3173 @ChgAdded{Version=[2],Text=[Clarified the wording so that the finalization
3174 takes place after the termination of the task or when the instance is
3175 finalized (whichever is sooner).]}
3176 @end{Diffword95}
3177
3178 @LabeledAddedSubClause{Version=[2],Name=[The Package Task_Termination]}
3179
3180 @begin{StaticSem}
3181
3182 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3183 @ChgAdded{Version=[2],KeepNext=[T],Type=[Leading],Text=[The following
3184 language-defined library package exists:]}
3185 @begin{Example}
3186 @ChgRef{Version=[2],Kind=[AddedNormal]}
3187 @ChgRef{Version=[5],Kind=[Revised],ARef=[AI12-0241-1]}
3188 @ChgAdded{Version=[2],Text=[@key<with> Ada.Task_Identification;
3189 @key<with> Ada.Exceptions;
3190 @key<package> Ada.Task_Termination@Chg{Version=[5],New=[],Old=[ @key<is>]}@ChildUnit{Parent=[Ada],Child=[Task_Termination]}
3191 @Chg{Version=[5],New=[@key<with>],Old=[@key<pragma>]} Preelaborate@Chg{Version=[5],New=[, Nonblocking @key[is]],Old=[(Task_Termination);]}]}
3192
3193 @ChgRef{Version=[2],Kind=[AddedNormal]}
3194 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Cause_Of_Termination} @key<is> (Normal, Abnormal, Unhandled_Exception);]}
3195
3196 @ChgRef{Version=[2],Kind=[AddedNormal]}
3197 @ChgAdded{Version=[2],Text=[ @key<type> @AdaTypeDefn{Termination_Handler} @key<is access protected procedure>
3198 (Cause : @key<in> Cause_Of_Termination;
3199 T : @key<in> Ada.Task_Identification.Task_Id;
3200 X : @key<in> Ada.Exceptions.Exception_Occurrence);]}
3201
3202 @ChgRef{Version=[2],Kind=[AddedNormal]}
3203 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Set_Dependents_Fallback_Handler}
3204 (Handler: @key<in> Termination_Handler);
3205 @key<function> @AdaSubDefn{Current_Task_Fallback_Handler} @key<return> Termination_Handler;]}
3206
3207 @ChgRef{Version=[2],Kind=[AddedNormal]}
3208 @ChgAdded{Version=[2],Text=[ @key<procedure> @AdaSubDefn{Set_Specific_Handler}
3209 (T : @key<in> Ada.Task_Identification.Task_Id;
3210 Handler : @key<in> Termination_Handler);
3211 @key<function> @AdaSubDefn{Specific_Handler} (T : Ada.Task_Identification.Task_Id)
3212 @key<return> Termination_Handler;]}
3213
3214 @ChgRef{Version=[2],Kind=[AddedNormal]}
3215 @ChgAdded{Version=[2],Text=[@key<end> Ada.Task_Termination;]}
3216 @end{Example}
3217
3218 @end{StaticSem}
3219
3220 @begin{RunTime}
3221
3222 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3223 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0202-1]}
3224 @ChgAdded{Version=[2],Text=[@Defn{termination handler}@Defn2{Term=[handler],Sec=[termination]}
3225 The type Termination_Handler identifies a protected
3226 procedure to be executed by the implementation when a task terminates. Such a
3227 protected procedure is called a @i<handler>. In all cases T identifies the task
3228 that is terminating. If the task terminates due to completing the last
3229 statement of its body, or as a result of waiting on a terminate alternative,
3230 @Chg{Version=[3],New=[and the finalization of the task completes normally, ],Old=[]}then
3231 Cause is set to Normal and X is set to Null_Occurrence. If the task
3232 terminates because it is being aborted, then Cause is set to
3233 Abnormal@Chg{Version=[3],New=[;],Old=[ and]} X is set to
3234 Null_Occurrence@Chg{Version=[3],New=[ if the finalization of the task completes normally],Old=[]}.
3235 If the task terminates because of an exception raised
3236 by the execution of its @nt{task_body}, then Cause is set to
3237 Unhandled_Exception@Chg{Version=[3],New=[;],Old=[ and]} X is set to the
3238 associated exception occurrence@Chg{Version=[3],New=[ if the finalization
3239 of the task completes normally],Old=[]}.@Chg{Version=[3],New=[ Independent of
3240 how the task completes, if finalization of the task propagates an exception,
3241 then Cause is either Unhandled_Exception or Abnormal, and X is an exception
3242 occurrence that identifies the Program_Error exception.],Old=[]}]}
3243
3244 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3245 @ChgAdded{Version=[2],Text=[@Defn{fall-back handler}@Defn2{Term=[termination handler],Sec=[fall-back]}
3246 @Defn{specific handler}@Defn2{Term=[termination handler],Sec=[specific]}
3247 @Defn2{Term=[set],Sec=[termination handler]}
3248 @Defn2{Term=[cleared],Sec=[termination handler]}
3249 Each task has two termination handlers, a @i<fall-back handler> and a
3250 @i<specific handler>. The specific handler applies only to the task itself,
3251 while the fall-back handler applies only to the dependent tasks of the task.
3252 A handler is said to be @i<set> if it is associated
3253 with a nonnull value of type Termination_Handler, and @i<cleared> otherwise.
3254 When a task is created, its specific handler and fall-back handler are cleared.]}
3255
3256 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3257 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3258 @ChgAdded{Version=[2],Text=[The procedure Set_Dependents_Fallback_Handler
3259 changes the fall-back handler for the calling
3260 task@Chg{Version=[3],New=[:],Old=[;]} if Handler is @key{null},
3261 that fall-back handler is cleared@Chg{Version=[3],New=[;],Old=[,]}
3262 otherwise@Chg{Version=[3],New=[,],Old=[]} it is set to be Handler.@key{all}.
3263 If a fall-back handler had previously been set it is replaced.]}
3264
3265 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3266 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3267 @ChgAdded{Version=[2],Text=[The function Current_Task_Fallback_Handler returns
3268 the fall-back handler that is currently set for the calling task, if one is
3269 set; otherwise@Chg{Version=[3],New=[,],Old=[]} it returns @key{null}.]}
3270
3271 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3272 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3273 @ChgAdded{Version=[2],Text=[The procedure Set_Specific_Handler changes the
3274 specific handler for the task identified by
3275 T@Chg{Version=[3],New=[:],Old=[;]} if Handler is @key{null}, that
3276 specific handler is cleared@Chg{Version=[3],New=[;],Old=[,]}
3277 otherwise@Chg{Version=[3],New=[,],Old=[]} it is set to be Handler.@key{all}. If
3278 a specific handler had previously been set it is replaced.]}
3279
3280 @begin{Ramification}
3281 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]}
3282 @ChgAdded{Version=[3],Text=[This package cannot portably be used to set
3283 a handler on the program as a whole. It is possible to call
3284 Set_Specific_Handler with the environment task's ID. But any call to the
3285 handler would necessarily be a @BoundedName, as the handler is called
3286 after the task's finalization has completed. In the case of the environment
3287 task, that includes any possible protected objects, and calling a protected
3288 object after it is finalized is a @BoundedName
3289 (see @RefSecNum{Protected Units and Protected Objects}). This might work in
3290 a particular implementation, but it cannot be depended upon.]}
3291 @end{Ramification}
3292
3293 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3294 @ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0264-1]}
3295 @ChgAdded{Version=[2],Text=[The function Specific_Handler returns the specific
3296 handler that is currently set for the task identified by T, if one is set;
3297 otherwise@Chg{Version=[3],New=[,],Old=[]} it returns @key{null}.]}
3298
3299 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3300 @ChgAdded{Version=[2],Text=[As part of the finalization of a @nt{task_body},
3301 after performing the actions specified in
3302 @RefSecNum{Assignment and Finalization} for finalization of a
3303 master, the specific handler for the task, if one is set, is executed.
3304 If the specific handler is cleared, a search
3305 for a fall-back handler proceeds by recursively following the master
3306 relationship for the task. If a task is found whose fall-back handler is set,
3307 that handler is executed; otherwise, no handler is executed.]}
3308
3309 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3310 @ChgAdded{Version=[2],Text=[For Set_Specific_Handler or
3311 Specific_Handler, Tasking_Error is raised if the task identified by T has
3312 already terminated. Program_Error is raised if the value of T is
3313 Ada.Task_Identification.Null_Task_Id.]}
3314
3315 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3316 @ChgAdded{Version=[2],Text=[An exception propagated from a handler that is
3317 invoked as part of the termination of a task has no effect.]}
3318
3319 @end{RunTime}
3320
3321 @begin{Erron}
3322 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3323 @ChgAdded{Version=[2],Text=[For a call of Set_Specific_Handler or
3324 Specific_Handler, if the task identified by T no longer exists, the execution
3325 of the program is erroneous.]}
3326 @end{Erron}
3327
3328 @begin{Extend95}
3329 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00266-02]}
3330 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3331 Package Task_Termination is new.]}
3332 @end{Extend95}
3333
3334 @begin{DiffWord2005}
3335 @ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0202-1]}
3336 @ChgAdded{Version=[3],Text=[@b<Correction:> Specified what is passed to the
3337 handler if the finalization of the task fails after it is completed. This was
3338 not specified at all in Ada 2005, so there is a possibility that some program
3339 depended on some other behavior of an implementation. But as this case is
3340 very unlikely (and only occurs when there is already a significant bug in
3341 the program - so should not occur in fielded systems), we're not listing
3342 this as an inconsistency.]}
3343 @end{DiffWord2005}