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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,39415b6b54268a8 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!b25g2000prb.googlegroups.com!not-for-mail From: Anh Vo Newsgroups: comp.lang.ada Subject: Re: Timing_Events: Event time still set after Cancel_Handler Date: Mon, 14 Sep 2009 14:20:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 149.32.224.33 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1252963200 778 127.0.0.1 (14 Sep 2009 21:20:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 14 Sep 2009 21:20:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b25g2000prb.googlegroups.com; posting-host=149.32.224.33; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; .NET CLR 3.0.04506.648),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:8324 Date: 2009-09-14T14:20:00-07:00 List-Id: On Sep 14, 9:12=A0am, Reto Buerki wrote: > 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 > > =A0 =A0use Ada.Real_Time.Timing_Events; > > =A0 =A0protected type Timer_Type is > =A0 =A0 =A0 procedure Setup (At_Time : Ada.Real_Time.Time); > =A0 =A0 =A0 function Get_Time return Ada.Real_Time.Time; > =A0 =A0 =A0 procedure Stop (Status : out Boolean); > =A0 =A0private > =A0 =A0 =A0 procedure Handle (Event : in out Timing_Event); > > =A0 =A0 =A0 Event : Timing_Event; > =A0 =A0end Timer_Type; > > end Timers; > > -- > > package body Timers is > > =A0 =A0protected body Timer_Type is > > =A0 =A0 =A0 function Get_Time return Ada.Real_Time.Time is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0return Event.Time_Of_Event; > =A0 =A0 =A0 end Get_Time; > > =A0 =A0 =A0 procedure Handle (Event : in out Timing_Event) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0null; > =A0 =A0 =A0 end Handle; > > =A0 =A0 =A0 procedure Setup (At_Time : Ada.Real_Time.Time) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Event.Set_Handler (At_Time =3D> At_Time, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Handler =3D> Hand= le'Access); > =A0 =A0 =A0 end Setup; > > =A0 =A0 =A0 procedure Stop (Status : out Boolean) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Event.Cancel_Handler (Cancelled =3D> Status); > =A0 =A0 =A0 end Stop; > > =A0 =A0end Timer_Type; > > end Timers; > > -- > > with Ada.Text_IO; > with Ada.Real_Time; > > with Timers; > > procedure Cancel_Handler is > =A0 =A0use Ada.Real_Time; > > =A0 =A0Handler : Timers.Timer_Type; > =A0 =A0Timer =A0 : constant Time :=3D Clock + Minutes (60); > begin > =A0 =A0if Handler.Get_Time =3D Time_First then > =A0 =A0 =A0 Ada.Text_IO.Put_Line ("Time is Time_First ..."); > =A0 =A0end if; > > =A0 =A0Handler.Setup (At_Time =3D> Timer); > =A0 =A0if Handler.Get_Time =3D Timer then > =A0 =A0 =A0 Ada.Text_IO.Put_Line ("Handler set ..."); > =A0 =A0end if; > > =A0 =A0declare > =A0 =A0 =A0 Stopped : Boolean :=3D False; > =A0 =A0begin > =A0 =A0 =A0 Handler.Stop (Status =3D> Stopped); > > =A0 =A0 =A0 if Stopped then > =A0 =A0 =A0 =A0 =A0Ada.Text_IO.Put_Line ("Timer cancelled ..."); > =A0 =A0 =A0 =A0 =A0if Handler.Get_Time =3D Timer then > =A0 =A0 =A0 =A0 =A0 =A0 Ada.Text_IO.Put_Line ("Why is the time still set = then?"); > =A0 =A0 =A0 =A0 =A0end if; > =A0 =A0 =A0 end if; > =A0 =A0end; > > 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? I say it is a bug because ARM 18/2 is violated. Anh Vo