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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!nospam From: "John B. Matthews" Newsgroups: comp.lang.ada Subject: Re: Barrier re-evaluation issue with GNAT 4.3.2 Date: Thu, 01 Oct 2009 12:12:47 -0400 Organization: The Wasteland Message-ID: References: NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.0 Cancel-Lock: sha1:Rhz/2BXkX0T+VaEIPdFW0gsnnUQ= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: g2news2.google.com comp.lang.ada:8563 Date: 2009-10-01T12:12:47-04:00 List-Id: In article , "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 My_Alarm : Alarm_Clock.Alarm_Type; begin Ada.Text_IO.Put_Line ("Setting alarm ..."); My_Alarm.Set; Ada.Text_IO.Put_Line ("Waiting for alarm ..."); My_Alarm.Wait; Ada.Text_IO.Put_Line ("ALARM!!"); end Main; package Alarm_Clock is type Alarm_Type is tagged null record; procedure Set(Alarm : Alarm_Type); procedure Wait(Alarm : Alarm_Type); end Alarm_Clock; with Ada.Real_Time.Timing_Events; package body Alarm_Clock is use Ada.Real_Time; Timer : Timing_Events.Timing_Event; Fired : Boolean := False; protected Clock is procedure Wakeup(Event : in out Timing_Events.Timing_Event); end Clock; protected body Clock is procedure Wakeup(Event : in out Timing_Events.Timing_Event) is begin Fired := True; end Wakeup; end Clock; procedure Set(Alarm : Alarm_Type) is begin Timer.Set_Handler(In_Time => Seconds(3), Handler => Clock.Wakeup'Access); end Set; procedure Wait(Alarm : Alarm_Type) is begin loop delay 1.0; exit when Fired; end loop; end Wait; end Alarm_Clock; -- John B. Matthews trashgod at gmail dot com