Annotated Ada Reference Manual (Ada 202y Draft 1)Legal Information
Contents   Index   References   Search   Previous   Next 

D.16 Multiprocessor Implementation

1/3
{AI05-0171-1} {AI05-0299-1} This subclause allows implementations on multiprocessor platforms to be configured. 

Static Semantics

2/3
{AI05-0171-1} The following language-defined library package exists: 
3/5
{AI12-0241-1} {AI12-0302-1} package System.Multiprocessors
   with Preelaborate, Nonblocking, Global => in out synchronized is
4/3
   type CPU_Range is range 0 .. implementation-defined;
   Not_A_Specific_CPU : constant CPU_Range := 0;
   subtype CPU is CPU_Range range 1 .. CPU_Range'Last;
4.a.1/3
Implementation defined: The value of CPU_Range'Last in System.Multiprocessors.
5/3
   function Number_Of_CPUs return CPU;
end System.Multiprocessors;
6/3
{AI05-0171-1} A call of Number_Of_CPUs returns the number of processors available to the program. Within a given partition, each call on Number_Of_CPUs will return the same value.
7/5
{AI05-0229-1} {AI12-0281-1} For a task type (including the anonymous type of a single_task_declaration), protected type (including the anonymous type of a single_protected_declaration), or subprogram, the following language-defined representation aspect may be specified:
8/3
CPU
The aspect CPU is an expression, which shall be of type System.Multiprocessors.CPU_Range.
8.a/5
Aspect Description for CPU: Processor on which a given task, or calling task for a protected operation, should run.

Legality Rules

9/3
{AI05-0171-1} {AI05-0229-1} If the CPU aspect is specified for a subprogram, the expression shall be static.
10/5
{AI05-0229-1} {AI12-0281-1} The CPU aspect shall not be specified on a task or protected interface type.

Dynamic Semantics

11/5
{AI05-0171-1} {AI05-0229-1} {AI12-0081-1} {AI12-0281-1} The expression specified for the CPU aspect of a task or protected type is evaluated each time an object of the corresponding type is created (see 9.1 and 9.4). The CPU value is then associated with the object.
12/3
{AI05-0171-1} {AI05-0229-1} The CPU aspect has no effect if it is specified for a subprogram other than the main subprogram; the CPU value is not associated with any task.
13/3
{AI05-0171-1} {AI05-0229-1} The CPU value is associated with the environment task if the CPU aspect is specified for the main subprogram. If the CPU aspect is not specified for the main subprogram it is implementation defined on which processor the environment task executes. 
13.a.1/3
Implementation defined: The processor on which the environment task executes in the absence of a value for the aspect CPU.
14/5
{AI05-0171-1} {AI05-0264-1} {AI12-0281-1} For a task, the CPU value determines the processor on which the task will activate and execute; the task is said to be assigned to that processor. If the CPU value is Not_A_Specific_CPU, then the task is not assigned to a processor. A task without a CPU aspect specified will activate and execute on the same processor as its activating task if the activating task is assigned a processor. If the CPU value is not in the range of System.Multiprocessors.CPU_Range or is greater than Number_Of_CPUs the task is defined to have failed, and it becomes a completed task (see 9.2).
15/5
{AI12-0281-1} For a protected type, the CPU value determines the processor on which calling tasks will execute; the protected object is said to be assigned to that processor. If the CPU value is Not_A_Specific_CPU, then the protected object is not assigned to a processor. A call to a protected object that is assigned to a processor from a task that is not assigned a processor or is assigned a different processor raises Program_Error.
15.a/5
Discussion: {AI12-0005-1} When a protected object is assigned to a CPU, only tasks also assigned to that CPU can call it. In contrast, a protected object that is not assigned to a specific CPU can be called by any task on any processor (subject, of course, to visibility and ceiling priority restrictions). As noted below, when the tasks and protected object are necessarily on the same CPU, a simpler implementation can be used. 

Implementation Advice

16/5
{AI12-0281-1} {AI12-0323-1} Starting a protected action on a protected object statically assigned to a processor should be implemented without busy-waiting.
16.a/5
Reason: Busy-waiting is a form of lock and can be a source of deadlock. Busy-waiting is typically needed for starting protected actions on multiprocessors, but if all tasks calling a protected object execute on the same CPU, this locking isn't needed and the source of deadlock and associated overhead can be eliminated.
16.b/5
Implementation Advice: Starting a protected action on a protected object statically assigned to a processor should not use busy-waiting.

Extensions to Ada 2005

16.c/3
{AI05-0171-1} {AI05-0229-1} The package System.Multiprocessors and the CPU aspect are new. 

Extensions to Ada 2012

16.d/5
{AI12-0281-1} Aspect CPU can now be applied to protected types, in order to avoid the overhead and deadlock potential of multiprocessor execution. 

Wording Changes from Ada 2012

16.e/4
{AI12-0081-1} Corrigendum: Clarified when the CPU aspect expression is evaluated.

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe