comp.lang.ada
 help / color / mirror / Atom feed
From: Per Dalgas Jakobsen <pdj@knaldgas.dk>
Subject: timer_server triggers Task_Termination handler
Date: Thu, 21 Apr 2016 12:23:50 +0200
Date: 2016-04-21T12:23:50+02:00	[thread overview]
Message-ID: <nfa9nm$bkc$1@loke.gir.dk> (raw)

Is it correct behaviour when tasks internal to the GNAT run-time causes 
users task_termination handlers to be called?

This behaviour is seen on:
   1) Debian Linux: gnat-5 (Ada 2005, Ada 2012).
   2) AIX: GNAT Pro 6.1.0w (Ada 2005).

A simple demonstration of the issue:

--------------------------------------------------------------------------------
with Ada.Text_IO;
with Log_Unhandled_Exceptions;

procedure Timer_Server_Noise is

begin
    Ada.Text_IO.Put_Line ("Start of main");

    select
       delay 0.5;
    then abort
       loop
          delay 0.1;
       end loop;
    end select;

    Ada.Text_IO.Put_Line ("End of main");
end  Timer_Server_Noise;
--------------------------------------------------------------------------------
with Ada.Exceptions;
with Ada.Task_Identification;
with Ada.Task_Termination;

package Log_Unhandled_Exceptions is

    pragma Elaborate_Body;

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

    --
    protected Last_Wishes is
       procedure Log_Any_Exit (Cause : in Cause_Of_Termination;
                               T     : in Task_Id;
                               E     : in Exception_Occurrence);
    end;

end Log_Unhandled_Exceptions;
--------------------------------------------------------------------------------
with Ada.Text_IO;


package body Log_Unhandled_Exceptions is

    -- Encapsulates the actual log call
    procedure Log (Text : in String) is
    begin
       Ada.Text_IO.Put_Line ("Log_Unhandled_Exceptions >> " &
                               Text);
    end Log;

    --
    protected body Last_Wishes is

       procedure Log_Any_Exit (Cause : in Cause_Of_Termination;
                               T     : in Task_Id;
                               E     : in Exception_Occurrence) is
       begin
          case Cause is
             when Normal =>
                Log ("Normal exit of task: " & Image (T));
             when Abnormal =>
                Log ("Abnormal exit of task: " & Image (T));
             when Unhandled_Exception =>
                Log ("Unhandled exception in task: " & Image (T));
          end case;
       end Log_Any_Exit;

    end Last_Wishes;


begin
    if Current_Task_Fallback_Handler = null then
       Set_Dependents_Fallback_Handler (Last_Wishes.Log_Any_Exit'Access);
    else
       Log ("Fallback handler already set, will not set own handler.");
    end if;

    if Specific_Handler (Current_Task) = null then
       Set_Specific_Handler (Current_Task, Last_Wishes.Log_Any_Exit'Access);

    else
       Log ("Specific handler already set, will not set own handler.");
    end if;
end Log_Unhandled_Exceptions;
--------------------------------------------------------------------------------

~Per

             reply	other threads:[~2016-04-21 10:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 10:23 Per Dalgas Jakobsen [this message]
2016-04-21 18:14 ` timer_server triggers Task_Termination handler Anh Vo
2016-04-21 18:20   ` Jacob Sparre Andersen
2016-04-21 18:31     ` Anh Vo
2016-04-21 21:13 ` Randy Brukardt
2016-04-22  5:41   ` J-P. Rosen
2016-04-22  6:46   ` Jacob Sparre Andersen
2016-04-21 21:26 ` Robert A Duff
2016-04-22  6:36   ` Georg Bauhaus
2016-04-22  7:25     ` Dmitry A. Kazakov
2016-04-22 10:05       ` G.B.
2016-04-22 12:55         ` Dmitry A. Kazakov
2016-04-22 13:33           ` G.B.
2016-04-22 13:42             ` Dmitry A. Kazakov
2016-04-22 22:31       ` Randy Brukardt
2016-04-23  9:55         ` Dmitry A. Kazakov
2016-04-25 21:42           ` Randy Brukardt
2016-04-22 22:35   ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox