comp.lang.ada
 help / color / mirror / Atom feed
* timer_server triggers Task_Termination handler
@ 2016-04-21 10:23 Per Dalgas Jakobsen
  2016-04-21 18:14 ` Anh Vo
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Per Dalgas Jakobsen @ 2016-04-21 10:23 UTC (permalink / 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

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2016-04-25 21:42 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-21 10:23 timer_server triggers Task_Termination handler Per Dalgas Jakobsen
2016-04-21 18:14 ` 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

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