CVS difference for ais/ai-10266.txt

Differences between 1.8 and version 1.9
Log of other versions for file ais/ai-10266.txt

--- ais/ai-10266.txt	2003/09/19 01:42:29	1.8
+++ ais/ai-10266.txt	2003/11/25 02:24:55	1.9
@@ -1,4 +1,4 @@
-!standard D.2.2 (5)                                03-08-17  AI95-00266-02/04
+!standard D.2.2 (5)                                03-11-24  AI95-00266-02/05
 !standard D.7 (00)
 !class amendment 01-06-01
 !status work item 01-06-01
@@ -25,43 +25,76 @@
 
 !proposal
 
-A package for handling task termination is defined as follows.
+(See wording.)
 
-with Ada.Task_Identification; use Task_Identification;
-with Ada.Exceptions; use Ada.Exceptions;
+!wording
+
+Add new section (not sure where)
+
+Task Termination Procedures
+
+This clause specifies a package for associating protected procedures
+with a task. One such procedure is invoked when the task is about to
+terminate.
+
+Static Semantics
+
+The following language-defined library package exists:
+
+with System;
+with Ada.Task_Identification;
+with Ada.Exceptions;
 package Ada.Task_Termination is
-  type Cause is (Normal, Abnormal, Unhandled_Exception);
+  type Cause_Of_Termination is (Normal, Abnormal, Unhandled_Exception);
 
   type Handler is access protected procedure(
-    C: Cause; Id: Task_Id; X: Exception_Occurrence := Null_Id);
-    -- Null_Id is used when cause is not Unhandler_Exception
+    Cause : Cause_Of_Termination;
+    T : Ada.Task_Identification.Task_Id;
+    X : Ada.Exceptions.Exception_Occurrence :=
+                    Ada.Exceptions.Null_Occurrence);
 
   procedure Set_Dependents_Default_Handler(New_Handler: in Handler);
-    -- Sets the default handler for all task dependents.
-    -- Handlers are not set on blocks, only on tasks
-    --
-    -- New_Handler is called immediately prior to dependent task termination.
-    -- If the task completed due to completing the last statement
-    -- of the task body, or as part of waiting on a terminate
-    -- alternative then C is set to Normal and no exception id
-    -- is given. If termination is due to abort then C is set
-    -- to Abnormal and no exception id is given. If termination is
-    -- due to a unhandled exception then C is set to Unhandled_
-    -- Exception and the associated exception id is set.
-
-  procedure Get_Handler(Old_Handler: out Handler);
-    -- Returns the previously set handler, or default or null.
-
-  procedure Set_Handler(Id : Task_Id; New_Handler: in Handler;
-            Old_Handler : out Handler);
-    -- A handler is set for the task; overriding any default. Old_Handler
-    -- returns any previously set handler, or default handler or null.
-    -- If a null handler is set then thsi re-estabilishes the default.
+  procedure Get_My_Default_Handler(Current_Handler: out Handler);
+
+  procedure Set_Handler(T : Ada.Task_Identification.Task_Id;
+                        New_Handler : in Handler);
+  procedure Get_Handler(T : Ada.Task_Identification.Task_Id;
+                        Current_Handler: out Handler);
 
 end Ada.Task_Termination;
 
-!wording
+Dynamic Semantics
+
+A call of Set_Dependents_Default_Handler sets the default handler
+for all tasks that are directly or indirectly dependent upon the
+calling task. It overrides for these dependent tasks any default
+handler in effect for the calling task. A call of
+Get_My_Default_Handler returns the default handler that is
+in effect for the calling task. If no default handler has been set
+it returns null.
+
+A call of Set_Handler sets a specific handler for the task identified
+by T. If a specific handler is already been set it is replaced by
+the new handler. A call of Get_Handler returns the specific handler if one
+has been set, otherwise the handler returned is null.
+
+When a task terminates, as part of its finalization a termination
+handler is identified. If there is a specific handler, it is executed;
+if not a default handler (if one is in effect) is executed.
+If the task terminated due to completing the last statement
+of the task body, or as part of waiting on a terminate
+alternative then Cause is set to Normal and no exception id
+is given. If termination is due to abort then Cause is set
+to Abnormal and no exception id is given. If termination is
+due to an unhandled exception then Cause is set to Unhandled_Exception
+and the associated exception occurrence is set.
+
+For all the operations and types defined in this package, Tasking_Error
+is raised if the task identified by T has already terminated. Program_Error
+is raised if the value of T is Null_Task_ID.
 
+An exception propogated from a handler that is invoked as part of
+a task's termination has no effect.
 
 !discussion
 
@@ -95,12 +128,8 @@
 supported by the proposal. The second involves adding to the existing
 default - this can be programmed by first getting the original default
 and then creating a new handler that incorporates the new functionality
-plus a call to the original handler. Note this would be much easier to
-program with an extendable protected type!
+plus a call to the original handler.
 
-When a call on Set_Handler is made and the task
-has already terminated then the handler is executed immediately.
-
 If a null default handler is set then this is equivalent to there being
 no handler.
 
@@ -108,12 +137,6 @@
 called after the task has been finalized but on the stack of the terminating
 task. Consequently, if Task_Identification.Current_Task is called from the
 handler, the terminating task identifier is returned.
-If the task has already terminated, the handler is called on the stack
-of the calling task, and Task_Identification.Current_Task
-returns the calling task.
-
-It is a bounded error for the user-supplied protected subprogram to
-propagate an exception.
 
 !example
 
@@ -134,10 +157,10 @@
 package Termination_Logging is -- library package
   protected Logger is
     entry Guardian_Control;
-    procedure Log_Termination(C : Cause;
-      Id: Task_Id; X: Exception_Occurrence := Null_Id);
-    procedure Output(C : Cause;
-      Id: Task_Id; X: Exception_Occurrence := Null_Id);
+    procedure Log_Termination(C : Cause_Of_Termination;
+      Id: Task_Id; X: Exception_Occurrence := Null_Occurrence);
+    procedure Output(C : Cause_Of_Termination;
+      Id: Task_Id; X: Exception_Occurrence := Null_Occurrence);
   private
     Abort_Occurrence : Boolean := False;
     Finished : Natural := 0;
@@ -152,33 +175,29 @@
     begin
       Abort_Occurrence := False;
     end Guardian_Control;
-    procedure Log_Termination (C : Cause;
-      Id: Task_Id; X: Exception_Occurrence := Null_Id) is
+    procedure Log_Termination (C : Cause_Of_Termination;
+      Id: Task_Id; X: Exception_Occurrence := Null_Occurrence) is
     begin
       Finished := Finished + 1;
-      if Cause = Unhandled_Exception then
+      if C = Unhandled_Exception then
         Exception_Finished := Exception_Finished + 1;
-      elsif Cause = Abnormal then
+      elsif C = Abnormal then
         Abort_Occurrence := True;
       end if;
     end Log_Termination;
-    procedure Output(C : Cause;
-      Id: Task_Id; X: Exception_Occurrence := Null_Id) is
+    procedure Output(C : Cause_Of_Termination;
+      Id: Task_Id; X: Exception_Occurrence := Null_Occurrence) is
     begin
       -- print out the values of Finished and Exception_Finished
     end Output;
     task body Guardian is ...
-    Temp : Handler;
   end Logger;
 begin
-  Set_Default_Handler(Logger.Log_Termination'Access);
-  Set_Handler(Current_Task, Logger.Output'Access, Temp);
+  Set_Dependents_Default_Handler(Logger.Log_Termination'Access);
+  Set_Handler(Current_Task, Logger.Output'Access);
 end Termination_Logging;
 
 !discussion
-
-Would it be useful to have a pragma to request the use of these
-facilities?
 
 !ACATS test
 

Questions? Ask the ACAA Technical Agent