From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Per Dalgas Jakobsen Newsgroups: comp.lang.ada Subject: timer_server triggers Task_Termination handler Date: Thu, 21 Apr 2016 12:23:50 +0200 Organization: JSA Research & Innovation Message-ID: NNTP-Posting-Host: 93.165.155.46 Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: loke.gir.dk 1461234230 11916 93.165.155.46 (21 Apr 2016 10:23:50 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 21 Apr 2016 10:23:50 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 X-Mozilla-News-Host: news://news.jacob-sparre.dk:119 Xref: news.eternal-september.org comp.lang.ada:30216 Date: 2016-04-21T12:23:50+02:00 List-Id: 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