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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,39415b6b54268a8,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!188.40.43.213.MISMATCH!feeder.eternal-september.org!eternal-september.org!not-for-mail From: Reto Buerki Newsgroups: comp.lang.ada Subject: Timing_Events: Event time still set after Cancel_Handler Date: Mon, 14 Sep 2009 18:12:14 +0200 Organization: A noiseless patient Spider Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: news.eternal-september.org U2FsdGVkX1/6dcCF5tOki3AIj1T79qsPdKeB9OZXtFgZZxrUDGWUi2NZdByvDvArbWSYK0NnQT31XfmXpkl2lZRwnWT0nDm6MO3gPu7R8AhYiqnhesIEvs4RdW0JwWpHlTOHYmdSJtw= X-Complaints-To: abuse@eternal-september.org NNTP-Posting-Date: Mon, 14 Sep 2009 16:12:12 +0000 (UTC) X-Auth-Sender: U2FsdGVkX1/VS9MlR0gbIxlQHoDfupnQ Cancel-Lock: sha1:weZtIkiWjZqY4ckmoDJ94Y8HIo0= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090706) Xref: g2news2.google.com comp.lang.ada:8321 Date: 2009-09-14T18:12:14+02:00 List-Id: Hi all, Before reporting a bug, I wanted to ask your opinion on this. Consider the following code: -- with Ada.Real_Time.Timing_Events; package Timers is use Ada.Real_Time.Timing_Events; protected type Timer_Type is procedure Setup (At_Time : Ada.Real_Time.Time); function Get_Time return Ada.Real_Time.Time; procedure Stop (Status : out Boolean); private procedure Handle (Event : in out Timing_Event); Event : Timing_Event; end Timer_Type; end Timers; -- package body Timers is protected body Timer_Type is function Get_Time return Ada.Real_Time.Time is begin return Event.Time_Of_Event; end Get_Time; procedure Handle (Event : in out Timing_Event) is begin null; end Handle; procedure Setup (At_Time : Ada.Real_Time.Time) is begin Event.Set_Handler (At_Time => At_Time, Handler => Handle'Access); end Setup; procedure Stop (Status : out Boolean) is begin Event.Cancel_Handler (Cancelled => Status); end Stop; end Timer_Type; end Timers; -- with Ada.Text_IO; with Ada.Real_Time; with Timers; procedure Cancel_Handler is use Ada.Real_Time; Handler : Timers.Timer_Type; Timer : constant Time := Clock + Minutes (60); begin if Handler.Get_Time = Time_First then Ada.Text_IO.Put_Line ("Time is Time_First ..."); end if; Handler.Setup (At_Time => Timer); if Handler.Get_Time = Timer then Ada.Text_IO.Put_Line ("Handler set ..."); end if; declare Stopped : Boolean := False; begin Handler.Stop (Status => Stopped); if Stopped then Ada.Text_IO.Put_Line ("Timer cancelled ..."); if Handler.Get_Time = Timer then Ada.Text_IO.Put_Line ("Why is the time still set then?"); end if; end if; end; end Cancel_Handler; -- The 'Timers' package provides a simple protected type 'Timer_Type' which basically just wraps an Ada.Real_Time.Timing_Events.Timing_Event type. The Setup() procedure can be used to set a specific event time. Stop() just calls the Cancel_Handler() procedure of the internal Timing_Event. This procedure 'clears' the event (if it is set). Ada RM D.15 about Real_Time.Timing Events states: 9/2 An object of type Timing_Event is said to be set if it is associated with a non-null value of type Timing_Event_Handler and cleared otherwise. All Timing_Event objects are initially cleared. 17/2 The procedure Cancel_Handler clears the event if it is set. Cancelled is assigned True if the event was set prior to it being cleared; otherwise it is assigned False. 18/2 The function Time_Of_Event returns the time of the event if the event is set; otherwise it returns Real_Time.Time_First. The RM does not explicitly state what happens with the event time value associated with a specific event after a call to Cancel_Handler(), but it seems logical to assume that Time_Of_Event should return Time_First again because no event is 'set' after it has been cleared (handler set to 'null'). With FSF GNAT, only the event handler is cleared, the event time remains set. Tested with GNAT 4.3.2 and 4.4.1 on Debian Stable/SID. Could this be considered as a bug? Thanks! - reto