[Home] [Prev] [Next] [Index]

C.7 Task Identification and Attributes

C.7 Task Identification and Attributes

1
[This clause describes operations and attributes that can be used to obtain the identity of a task.  In addition, a package that associates user-defined information with a task is defined.]

C.7.1 The Package Task_Identification

Static Semantics

1
The following language-defined library package exists:

2
package Ada.Task_Identification is

   type Task_ID is private;
   Null_Task_ID : constant Task_ID;
   function  "=" (Left, Right : Task_ID) return Boolean;

3
   function  Image        (T : Task_ID) return String;
   function  Current_Task return Task_ID;
   procedure Abort_Task   (T : in out Task_ID);

4
   function  Is_Terminated(T : Task_ID) return Boolean;
   function  Is_Callable  (T : Task_ID) return Boolean;
private
   ... -- not specified by the language
end Ada.Task_Identification;

Dynamic Semantics

5
A value of the type Task_ID identifies an existent task.  The constant Null_Task_ID does not identify any task.  Each object of the type Task_ID is default initialized to the value of Null_Task_ID.

6
The function "=" returns True if and only if Left and Right identify the same task or both have the value Null_Task_ID.

7
The function Image returns an implementation-defined string that identifies T.  If T equals Null_Task_ID, Image returns an empty string.

7.a
Implementation defined:  The result of the Task_Identification.Image attribute.

8
The function Current_Task returns a value that identifies the calling task.

9
The effect of Abort_Task is the same as the abort_statement for the task identified by T. [In addition, if T identifies the environment task, the entire partition is aborted, See E.1.]

10
The functions Is_Terminated and Is_Callable return the value of the corresponding attribute of the task identified by T.

11
For a prefix T that is of a task type [(after any implicit dereference)], the following attribute is defined:

12
T'Identity Yields a value of the type Task_ID that identifies the task denoted by T.

13
For a prefix E that denotes an entry_declaration, the following attribute is defined:

14
E'Caller Yields a value of the type Task_ID that identifies the task whose call is now being serviced.  Use of this attribute is allowed only inside an entry_body or accept_statement corresponding to the entry_declaration denoted by E.

15
Program_Error is raised if a value of Null_Task_ID is passed as a parameter to Abort_Task, Is_Terminated, and Is_Callable.

16
Abort_Task is a potentially blocking operation (see 9.5.1).

Bounded (Run-Time) Errors

17
It is a bounded error to call the Current_Task function from an entry body or an interrupt handler. Program_Error is raised, or an implementation-defined value of the type Task_ID is returned.

17.a
Implementation defined:  The value of Current_Task when in a protected entry or interrupt handler.

17.b
Implementation Note: This value could be Null_Task_ID, or the ID of some user task, or that of an internal task created by the implementation.

Erroneous Execution

18
If a value of Task_ID is passed as a parameter to any of the operations declared in this package (or any language-defined child of this package), and the corresponding task object no longer exists, the execution of the program is erroneous.

Documentation Requirements

19
The implementation shall document the effect of calling Current_Task from an entry body or interrupt handler.

19.a
Implementation defined:  The effect of calling Current_Task from an entry body or interrupt handler.

NOTES

20 10
This package is intended for use in writing user-defined task scheduling packages and constructing server tasks.  Current_Task can be used in conjunction with other operations requiring a task as an argument such as Set_Priority (see D.5).

21 11
The function Current_Task and the attribute Caller can return a Task_ID value that identifies the environment task.

C.7.2 The Package Task_Attributes

Static Semantics

1
The following language-defined generic library package exists:

2
with Ada.Task_Identification; use Ada.Task_Identification;
generic
   type Attribute is private;
   Initial_Value : in Attribute;

package Ada.Task_Attributes is

3
   type Attribute_Handle is access all Attribute;

4
   function Value(T : Task_ID := Current_Task)
     return Attribute;

5
   function Reference(T : Task_ID := Current_Task)
     return Attribute_Handle;

6
   procedure Set_Value(Val : in Attribute;
                             T : in Task_ID := Current_Task);
   procedure Reinitialize(T : in Task_ID := Current_Task);

7
end Ada.Task_Attributes;

Dynamic Semantics

8
When an instance of Task_Attributes is elaborated in a given active partition, an object of the actual type corresponding to the formal type Attribute is implicitly created for each task (of that partition) that exists and is not yet terminated. This object acts as a user-defined attribute of the task. A task created previously in the partition and not yet terminated has this attribute from that point on.  Each task subsequently created in the partition will have this attribute when created.  In all these cases, the initial value of the given attribute is Initial_Value.

9
The Value operation returns the value of the corresponding attribute of T.

10
The Reference operation returns an access value that designates the corresponding attribute of T.

11
The Set_Value operation performs any finalization on the old value of the attribute of T and assigns Val to that attribute (see 5.2 and 7.6).

12
The effect of the Reinitialize operation is the same as Set_Value where the Val parameter is replaced with Initial_Value.

12.a
Implementation Note: In most cases, the attribute memory can be reclaimed at this point.

13
For all the operations declared in this package, Tasking_Error is raised if the task identified by T is terminated. Program_Error is raised if the value of T is Null_Task_ID.

Erroneous Execution

14
It is erroneous to dereference the access value returned by a given call on Reference after a subsequent call on Reinitialize for the same task attribute, or after the associated task terminates.

14.a
Reason: This allows the storage to be reclaimed for the object associated with an attribute upon Reinitialize or task termination.

15
If a value of Task_ID is passed as a parameter to any of the operations declared in this package and the corresponding task object no longer exists, the execution of the program is erroneous.

Implementation Requirements

16
The implementation shall perform each of the above operations for a given attribute of a given task atomically with respect to any other of the above operations for the same attribute of the same task.

16.a
Ramification: Hence, other than by dereferencing an access value returned by Reference, an attribute of a given task can be safely read and updated concurrently by multiple tasks.

17
When a task terminates, the implementation shall finalize all attributes of the task, and reclaim any other storage associated with the attributes.

Documentation Requirements

18
The implementation shall document the limit on the number of attributes per task, if any, and the limit on the total storage for attribute values per task, if such a limit exists.

19
In addition, if these limits can be configured, the implementation shall document how to configure them.

19.a
Implementation defined:  Implementation-defined aspects of Task_Attributes.

Metrics

20
The implementation shall document the following metrics: A task calling the following subprograms shall execute in a sufficiently high priority as to not be preempted during the measurement period.  This period shall start just before issuing the call and end just after the call completes.  If the attributes of task T are accessed by the measurement tests, no other task shall access attributes of that task during the measurement period. For all measurements described here, the Attribute type shall be a scalar whose size is equal to the size of the predefined integer size. For each measurement, two cases shall be documented: one where the accessed attributes are of the calling task [(that is, the default value for the T parameter is used)], and the other, where T identifies another, non-terminated, task.

21
The following calls (to subprograms in the Task_Attributes package) shall be measured:

22 ·
a call to Value, where the return value is Initial_Value;

23 ·
a call to Value, where the return value is not equal to Initial_Value;

24 ·
a call to Reference, where the return value designates a value equal to Initial_Value;

25 ·
a call to Reference, where the return value designates a value not equal to Initial_Value;

26 ·
a call to Set_Value where the Val parameter is not equal to Initial_Value and the old attribute value is equal to Initial_Value.

27 ·
a call to Set_Value where the Val parameter is not equal to Initial_Value and the old attribute value is not equal to Initial_Value.

Implementation Permissions

28
An implementation need not actually create the object corresponding to a task attribute until its value is set to something other than that of Initial_Value, or until Reference is called for the task attribute. Similarly, when the value of the attribute is to be reinitialized to that of Initial_Value, the object may instead be finalized and its storage reclaimed, to be recreated when needed later. While the object does not exist, the function Value may simply return Initial_Value, rather than implicitly creating the object.

28.a
Discussion:  The effect of this permission can only be observed if the assignment operation for the corresponding type has side-effects.

28.b
Implementation Note: This permission means that even though every task has every attribute, storage need only be allocated for those attributes that have been Reference'd or set to a value other than that of Initial_Value.

29
An implementation is allowed to place restrictions on the maximum number of attributes a task may have, the maximum size of each attribute, and the total storage size allocated for all the attributes of a task.

Implementation Advice

30
Some implementations are targeted to domains in which memory use at run time must be completely deterministic.  For such implementations, it is recommended that the storage for task attributes will be pre-allocated statically and not from the  heap.  This can be accomplished by either placing restrictions on the number and the size of the task's attributes, or by using the pre-allocated storage for the first N attribute objects, and the heap for the others.  In the latter case, N should be documented.

NOTES

31 12
An attribute always exists (after instantiation), and has the initial value. It need not occupy memory until the first operation that potentially changes the attribute value.  The same holds true after Reinitialize.

32 13
The result of the Reference function should be used with care; it is always safe to use that result in the task body whose attribute is being accessed.  However, when the result is being used by another task, the programmer must make sure that the task whose attribute is being accessed is not yet terminated.  Failing  to do so could make the program execution erroneous.

33 14
As specified in C.7.1, if the parameter T (in a call on a subprogram of an instance of this package) identifies a nonexistent task, the execution of the program is erroneous.



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-1998, Rational Software Corporation.   All rights reserved.