Shared Variable Control
Author: JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor

Ada Reference Manual — Legal Information

# C.6 Shared Variable Control

1/3
This subclause defines representation aspects that control the use of shared variables.
Paragraphs 2 through 6 were moved to Annex J, “Obsolescent Features”.

#### Static Semantics

6.1/3
For an object_declaration, a component_declaration, or a full_type_declaration, the following representation aspects may be specified:
6.2/3
Atomic
The type of aspect Atomic is Boolean.
6.3/3
Independent
The type of aspect Independent is Boolean.
6.4/3
Volatile
The type of aspect Volatile is Boolean.
6.5/3
For a full_type_declaration of an array type (including the anonymous type of an object_declaration of an anonymous array object), the following representation aspects may be specified:
6.6/3
Atomic_Components
The type of aspect Atomic_Components is Boolean.
6.7/3
Volatile_Components
The type of aspect Volatile_Components is Boolean.
6.8/3
For a full_type_declaration (including the anonymous type of an object_declaration of an anonymous array object), the following representation aspect may be specified:
6.9/3
Independent_Components
The type of aspect Independent_Components is Boolean.
6.10/3
If any of these aspects are directly specified, the aspect_definition shall be a static expression. If not specified (including by inheritance), each of these aspects is False.
7/3
An atomic type is one for which the aspect Atomic is True. An atomic object (including a component) is one for which the aspect Atomic is True, or a component of an array for which the aspect Atomic_Components is True for the associated type, or any object of an atomic type, other than objects obtained by evaluating a slice.
8/3
A volatile type is one for which the aspect Volatile is True. A volatile object (including a component) is one for which the aspect Volatile is True, or a component of an array for which the aspect Volatile_Components is True for the associated type, or any object of a volatile type. In addition, every atomic type or object is also defined to be volatile. Finally, if an object is volatile, then so are all of its subcomponents (the same does not apply to atomic).
8.1/3
When True, the aspects Independent and Independent_Components specify as independently addressable the named object or component(s), or in the case of a type, all objects or components of that type. All atomic objects are considered to be specified as independently addressable.
Paragraph 9 was moved to Annex J, “Obsolescent Features”.

#### Legality Rules

9.1/3
If aspect Independent_Components is specified for a full_type_declaration, the declaration shall be that of an array or record type.
10/3
It is illegal to specify either of the aspects Atomic or Atomic_Components to have the value True for an object or type if the implementation cannot support the indivisible reads and updates required by the aspect (see below).
11
It is illegal to specify the Size attribute of an atomic object, the Component_Size attribute for an array type with atomic components, or the layout attributes of an atomic component, in a way that prevents the implementation from performing the required indivisible reads and updates.
12/3
If an atomic object is passed as a parameter, then the formal parameter shall either have an atomic type or allow pass by copy. If an atomic object is used as an actual for a generic formal object of mode in out, then the type of the generic formal object shall be atomic. If the prefix of an attribute_reference for an Access attribute denotes an atomic object (including a component), then the designated type of the resulting access type shall be atomic. If an atomic type is used as an actual for a generic formal derived type, then the ancestor of the formal type shall be atomic. Corresponding rules apply to volatile objects and types.
12.1/3
If a volatile type is used as an actual for a generic formal array type, then the element type of the formal type shall be volatile.
13/3
If an aspect Volatile, Volatile_Components, Atomic, or Atomic_Components is directly specified to have the value True for a stand-alone constant object, then the aspect Import shall also be specified as True for it.
13.1/3
It is illegal to specify the aspect Independent or Independent_Components as True for a component, object or type if the implementation cannot provide the independent addressability required by the aspect (see 9.10).
13.2/3
It is illegal to specify a representation aspect for a component, object or type for which the aspect Independent or Independent_Components is True, in a way that prevents the implementation from providing the independent addressability required by the aspect.
Paragraph 14 was moved to Annex J, “Obsolescent Features”.

#### Dynamic Semantics

15
For an atomic object (including an atomic component) all reads and updates of the object as a whole are indivisible.
16/3
All tasks of the program (on all processors) that read or update volatile variables see the same order of updates to the variables. A use of an atomic variable or other mechanism may be necessary to avoid erroneous execution and to ensure that access to nonatomic volatile variables is sequential (see 9.10).
17
Two actions are sequential (see 9.10) if each is the read or update of the same atomic object.
18
If a type is atomic or volatile and it is not a by-copy type, then the type is defined to be a by-reference type. If any subcomponent of a type is atomic or volatile, then the type is defined to be a by-reference type.
19
If an actual parameter is atomic or volatile, and the corresponding formal parameter is not, then the parameter is passed by copy.

#### Implementation Requirements

20
The external effect of a program (see 1.1.3) is defined to include each read and update of a volatile or atomic object. The implementation shall not generate any memory reads or updates of atomic or volatile objects other than those specified by the program.
21/3
If the Pack aspect is True for a type any of whose subcomponents are atomic, the implementation shall not pack the atomic subcomponents more tightly than that for which it can support indivisible reads and updates.

#### Implementation Advice

22/2
A load or store of a volatile object whose size is a multiple of System.Storage_Unit and whose alignment is nonzero, should be implemented by accessing exactly the bits of the object and no others.
23/2
A load or store of an atomic object should, where possible, be implemented by a single load or store instruction.
NOTES
24
9 An imported volatile or atomic constant behaves as a constant (i.e. read-only) with respect to other parts of the Ada program, but can still be modified by an “external source.”

Ada 2005 and 2012 Editions sponsored in part by Ada-Europe