From: "John B. Matthews" <nospam@nospam.invalid>
Subject: Re: Barrier re-evaluation issue with GNAT 4.3.2
Date: Thu, 01 Oct 2009 22:26:05 -0400
Date: 2009-10-01T22:26:05-04:00 [thread overview]
Message-ID: <nospam-1D58ED.22260501102009@news.aioe.org> (raw)
In-Reply-To: 3c32a0db-9878-4057-b3b8-44d03f02571d@z3g2000prd.googlegroups.com
In article
<3c32a0db-9878-4057-b3b8-44d03f02571d@z3g2000prd.googlegroups.com>,
Anh Vo <anhvofrcaus@gmail.com> wrote:
> On Oct 1, 9:12 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
> > In article <nospam-12AAE0.11590930092...@news.aioe.org>,
> > "John B. Matthews" <nos...@nospam.invalid> 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
<http://sites.google.com/site/drjohnbmatthews>
prev parent reply other threads:[~2009-10-02 2:26 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-24 17:02 Barrier re-evaluation issue with GNAT 4.3.2 Reto Buerki
2009-09-24 17:47 ` Dmitry A. Kazakov
2009-09-25 8:50 ` Brad Moore
2009-09-25 9:17 ` Dmitry A. Kazakov
2009-09-25 9:57 ` Ludovic Brenta
2009-09-25 10:31 ` Dmitry A. Kazakov
2009-09-25 11:23 ` Jean-Pierre Rosen
2009-09-28 10:41 ` Reto Buerki
2009-09-25 17:06 ` Brad Moore
2009-09-25 18:42 ` Dmitry A. Kazakov
2009-09-25 19:39 ` Brad Moore
2009-09-28 10:18 ` Reto Buerki
2009-09-25 15:56 ` John B. Matthews
2009-09-26 14:23 ` John B. Matthews
2009-09-28 10:28 ` Reto Buerki
2009-09-28 12:39 ` John B. Matthews
2009-09-28 13:25 ` Reto Buerki
2009-09-28 14:05 ` Reto Buerki
2009-09-28 18:38 ` Jeffrey R. Carter
2009-09-28 18:51 ` Dmitry A. Kazakov
2009-09-29 8:37 ` Reto Buerki
2009-09-28 21:13 ` Robert A Duff
2009-09-28 22:28 ` Jeffrey R. Carter
2009-10-10 5:41 ` Randy Brukardt
2009-09-29 8:30 ` Reto Buerki
2009-09-29 15:06 ` John B. Matthews
2009-09-30 14:12 ` Reto Buerki
2009-09-30 15:59 ` John B. Matthews
2009-10-01 16:12 ` John B. Matthews
2009-10-01 17:17 ` Anh Vo
2009-10-02 2:26 ` John B. Matthews [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox