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,a4db0fc323f0b09e X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!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 22:26:05 -0400 Organization: The Wasteland Message-ID: References: <3c32a0db-9878-4057-b3b8-44d03f02571d@z3g2000prd.googlegroups.com> NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.0 Cancel-Lock: sha1:EvVZoMkpcSRpSIX45aIO1y6TGm0= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: g2news2.google.com comp.lang.ada:8567 Date: 2009-10-01T22:26:05-04:00 List-Id: In article <3c32a0db-9878-4057-b3b8-44d03f02571d@z3g2000prd.googlegroups.com>, Anh Vo wrote: > On Oct 1, 9:12 am, "John B. Matthews" wrote: > > 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: [...] > >    type Alarm_Type is tagged null record; [...] > I am curious why Alarm_Type is even needed in this case. Good question. It's not. I was tinkering with several implementation that matched a variant of the OP's main. As this is a work-around, I wanted to preserve the calling style, which used the prefixed notation. That style was available to protected types in Ada 95 and was extended to tagged types in Ada 05. I didn't realize how much I liked the notation until I stared using Ada.Containers. > 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. Good catch; thank you. Set should clear Fired. Another work-around implementation is shown below. Entering Signal from the protected procedure Wakeup is a bounded error (LRM 9.5.1(11)), and the compiler (FSF GNAT 4.3.4) issues a corresponding compile time warning. Interestingly, using pragma Detect_Blocking does not raise Program_Error. I'm curious to know whether that's just a reasonable limitation in how the pragma is implemented, or is the entry call reasonable in this context. with Ada.Real_Time.Timing_Events; package Alarm_Clock is use Ada.Real_Time; protected type Alarm_Type is procedure Set; entry Wait; entry Signal; end Alarm_Type; end Alarm_Clock; Pragma Detect_Blocking; package body Alarm_Clock is Timer : Timing_Events.Timing_Event; protected body Alarm_Type is procedure Wakeup(Event : in out Timing_Events.Timing_Event) is begin Signal; end Wakeup; procedure Set is begin Timer.Set_Handler(In_Time => Seconds (1), Handler => Wakeup'Access); end Set; entry Wait when Signal'Count > 0 is begin null; end Wait; entry Signal when Wait'Count = 0 is begin null; end Signal; end Alarm_Type; end Alarm_Clock; -- John B. Matthews trashgod at gmail dot com