Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
Annotated Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

C.7.1 The Package Task_Identification

Static Semantics

The following language-defined library package exists: 
{AI95-00362-01} {AI12-0241-1} {AI12-0302-1} {AI12-0399-1} package Ada.Task_Identification is
   with pragma Preelaborate, Nonblocking, Global => in out synchronized is(Task_Identification);
   type Task_Id is private;
      with pragma Preelaborable_Initialization (Task_Id);
   Null_Task_Id : constant Task_Id;
   function  "=" (Left, Right : Task_Id) return Boolean;
{8652/0070} {AI95-00101-01} {AI05-0189-1} {AI12-0241-1}    function  Image                  (T : Task_Id) return String;
   function  Current_Task     return Task_Id;
   function  Environment_Task return Task_Id;
   procedure Abort_Task             (T : in Task_Id)
      with Nonblocking => False
{AI05-0189-1}    function  Is_Terminated          (T : Task_Id) return Boolean;
   function  Is_Callable            (T : Task_Id) return Boolean;
   function  Activation_Is_Complete (T : Task_Id) return Boolean;
   ... -- not specified by the language
end Ada.Task_Identification;

Dynamic Semantics

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.
The function "=" returns True if and only if Left and Right identify the same task or both have the value Null_Task_Id.
The function Image returns an implementation-defined string that identifies T. If T equals Null_Task_Id, Image returns an empty string. 
Implementation defined: The result of the Task_Identification.Image attribute.
The function Current_Task returns a value that identifies the calling task.
Ramification: {AI12-0005-1} The logical threads of control associated with the execution of a given parallel construct all execute as part of the execution of one task (see 9, “Tasks and Synchronization”). Thus, the result returned by a call to Task_Identification.Current_Task is independent of whether the call takes place during the execution of a parallel construct. 
 {AI05-0189-1} The function Environment_Task returns a value that identifies the environment task.
{AI12-0454-1} 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 See E.1.]
The functions Is_Terminated and Is_Callable return the value of the corresponding attribute of the task identified by T.
Ramification: {8652/0115} {AI95-00206-01} These routines can be called with an argument identifying the environment task. Is_Terminated will always be False for such a call, but Is_Callable (usually True) could be False if the environment task is waiting for the termination of dependent tasks. Thus, a dependent task can use Is_Callable to determine if the main subprogram has completed. 
  {AI05-0189-1} The function Activation_Is_Complete returns True if the task identified by T has completed its activation (whether successfully or not). It returns False otherwise. If T identifies the environment task, Activation_Is_Complete returns True after the elaboration of the library_items of the partition has completed.
For a prefix T that is of a task type [(after any implicit dereference)], the following attribute is defined: 
Yields a value of the type Task_Id that identifies the task denoted by T.
For a prefix E that denotes an entry_declaration, the following attribute is defined: 
{AI05-0262-1} 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 accept_statement, or entry_body after the entry_barrier, corresponding to the entry_declaration denoted by E. 
{AI12-0231-1} Program_Error is raised if a value of Null_Task_Id is passed as a parameter to Abort_Task, Activation_Is_Complete, Is_Terminated, and Is_Callable.
This paragraph was deleted.{AI12-0241-1} Abort_Task is a potentially blocking operation (see 9.5.1).

Bounded (Run-Time) Errors

{AI95-00237-01} {AI05-0004-1} It is a bounded error to call the Current_Task function from an entry_body, interrupt handler, or finalization of a task attribute. Program_Error is raised, or an implementation-defined value of the type Task_Id is returned. 
Implementation defined: The value of Current_Task when in a protected entry, interrupt handler, or finalization of a task attribute.
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. 
Ramification: {AI95-00237-01} An entry barrier is syntactically part of an entry_body, so a call to Current_Task from an entry barrier is also covered by this rule. 

Erroneous Execution

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

The implementation shall document the effect of calling Current_Task from an entry body or interrupt handler. 
This paragraph was deleted.
Documentation Requirement: The effect of calling Current_Task from an entry body or interrupt handler.
NOTE 1   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).
NOTE 2   The function Current_Task and the attribute Caller can return a Task_Id value that identifies the environment task.

Extensions to Ada 95

{AI95-00362-01} Task_Identification is now preelaborated, so it can be used in preelaborated units. 

Wording Changes from Ada 95

{8652/0070} {AI95-00101-01} Corrigendum: Corrected the mode of the parameter to Abort_Task to in.
{AI95-00237-01} Corrected the wording to include finalization of a task attribute in the bounded error case; we don't want to specify which task does these operations. 

Incompatibilities With Ada 2005

{AI05-0189-1} Functions Environment_Task and Activation_Is_Complete are added to Task_Identification. If Task_Identification is referenced in a use_clause, and an entity E with a defining_identifier of Environment_Task or Activation_Is_Complete is defined in a package that is also referenced in a use_clause, the entity E may no longer be use-visible, resulting in errors. This should be rare and is easily fixed if it does occur. 

Wording Changes from Ada 2012

{AI12-0231-1} Correction: Defined what happens if Null_Task_Id is passed to Activation_Is_Complete. 

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