This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fall-back termination handlers does not apply to Self


This patch fixes a small missunderstanding in the implementation of fall-back
termination handlers. Previously, a fall-back termination handler set by a
given task would apply for itself. However, it has been now corrected because
it applies only to dependent tasks (see ARM C.7.3 par. 9/2).

The following test case must generate only a "OK: expected handler" message,
corresponding to the termination of the Child task triggering the fall-back
termination handler set by its creator (and not the one set by task Child).

$ gnatmake -q -gnat05 terminate_hierarchy
$ terminate_hierarchy
OK: expected handler

-----

with Ada.Task_Termination; use Ada.Task_Termination;
with Tasking;              use Tasking;

procedure Terminate_Hierarchy is
begin
   Set_Dependents_Fallback_Handler (Monitor.Parent_Handler'Access);
   Child.Start;
end Terminate_Hierarchy;

with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Task_Termination;    use Ada.Task_Termination;
with Ada.Exceptions;          use Ada.Exceptions;

package Tasking is
   protected Monitor is
      procedure Parent_Handler
        (C  : Cause_Of_Termination;
         Id : Task_Id;
         X  : Exception_Occurrence := Null_Occurrence);

      procedure Child_Handler
        (C  : Cause_Of_Termination;
         Id : Task_Id;
         X  : Exception_Occurrence := Null_Occurrence);
   end Monitor;

   task Child is
      entry Start;
   end Child;
end Tasking;

with Ada.Text_IO; use Ada.Text_IO;

package body Tasking is

   protected body Monitor is
      procedure Parent_Handler
        (C  : Cause_Of_Termination;
         Id : Task_Id;
         X  : Exception_Occurrence := Null_Occurrence) is
      begin
         Put_Line ("OK: expected handler");
      end Parent_Handler;

      procedure Child_Handler
        (C  : Cause_Of_Termination;
         Id : Task_Id;
         X  : Exception_Occurrence := Null_Occurrence) is
      begin
         Put_Line ("KO: unexpected handler");
      end Child_Handler;
   end Monitor;

   task body Child is
   begin
      Set_Dependents_Fallback_Handler (Monitor.Child_Handler'Access);
      accept Start;
   end Child;

end Tasking;

Tested on x86_64-pc-linux-gnu, committed on trunk

2013-04-24  Jose Ruiz  <ruiz@adacore.com>

	* s-tassta.adb, s-tarest.adb (Task_Wrapper): Start looking for
	fall-back termination handlers from the parents, because they apply
	only to dependent tasks.
	* s-solita.adb (Task_Termination_Handler_T): Do not look for fall-back
	termination handlers because the environment task has no parent,
	and if it defines one of these handlers it does not apply to
	itself because they apply only to dependent tasks.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]