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,a4db0fc323f0b09e X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!z3g2000prd.googlegroups.com!not-for-mail From: Anh Vo Newsgroups: comp.lang.ada Subject: Re: Barrier re-evaluation issue with GNAT 4.3.2 Date: Thu, 1 Oct 2009 10:17:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <3c32a0db-9878-4057-b3b8-44d03f02571d@z3g2000prd.googlegroups.com> References: NNTP-Posting-Host: 149.32.224.34 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1254417444 14380 127.0.0.1 (1 Oct 2009 17:17:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 1 Oct 2009 17:17:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z3g2000prd.googlegroups.com; posting-host=149.32.224.34; 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:8564 Date: 2009-10-01T10:17:24-07:00 List-Id: On Oct 1, 9:12=A0am, "John B. Matthews" wrote: > In article , > =A0"John B. Matthews" wrote: > > [...] > > > Another alternative, suggested by Dmitry A. Kazakov, is to replace > > entry Wait with procedure Wait, which obviates the need for Signal: > > Sorry, I carelessly posted code with a busy-wait. Please consider this > alternative, which polls the timer's state: > > with Ada.Text_IO; > with Alarm_Clock; > > procedure Main is > =A0 =A0My_Alarm : Alarm_Clock.Alarm_Type; > begin > =A0 =A0Ada.Text_IO.Put_Line ("Setting alarm ..."); > =A0 =A0My_Alarm.Set; > > =A0 =A0Ada.Text_IO.Put_Line ("Waiting for alarm ..."); > =A0 =A0My_Alarm.Wait; > > =A0 =A0Ada.Text_IO.Put_Line ("ALARM!!"); > end Main; > > package Alarm_Clock is > > =A0 =A0type Alarm_Type is tagged null record; > =A0 =A0procedure Set(Alarm : Alarm_Type); > =A0 =A0procedure Wait(Alarm : Alarm_Type); > > end Alarm_Clock; > > with Ada.Real_Time.Timing_Events; > > package body Alarm_Clock is > > =A0 =A0use Ada.Real_Time; > =A0 =A0Timer : Timing_Events.Timing_Event; > =A0 =A0Fired : Boolean :=3D False; > > =A0 =A0protected Clock is > =A0 =A0 =A0 procedure Wakeup(Event : in out Timing_Events.Timing_Event); > =A0 =A0end Clock; > > =A0 =A0protected body Clock is > =A0 =A0 =A0 procedure Wakeup(Event : in out Timing_Events.Timing_Event) i= s > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Fired :=3D True; > =A0 =A0 =A0 end Wakeup; > =A0 =A0end Clock; > > =A0 =A0procedure Set(Alarm : Alarm_Type) is > =A0 =A0begin > =A0 =A0 =A0 Timer.Set_Handler(In_Time =3D> Seconds(3), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Handler =3D> Clock.Wakeup= 'Access); > =A0 =A0end Set; > > =A0 =A0procedure Wait(Alarm : Alarm_Type) is > =A0 =A0begin > =A0 =A0 =A0 loop > =A0 =A0 =A0 =A0 =A0delay 1.0; > =A0 =A0 =A0 =A0 =A0exit when Fired; > =A0 =A0 =A0 end loop; > =A0 =A0end Wait; > > end Alarm_Clock; I am curious why Alarm_Type is even needed in this case. In addition, Alarm_Clock works the first time. However, it won't work right on the second time and on because Fired was not reset after the Alarm goes off. Anh Vo