From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Barrier re-evaluation issue with GNAT 4.3.2
Date: Fri, 25 Sep 2009 11:17:32 +0200
Date: 2009-09-25T11:17:32+02:00 [thread overview]
Message-ID: <rcfj2mz9pjnu$.pem92yd9ybip.dlg@40tude.net> (raw)
In-Reply-To: sv%um.246578$ZN.73934@newsfe23.iad
On Fri, 25 Sep 2009 02:50:32 -0600, Brad Moore wrote:
> Dmitry A. Kazakov wrote:
>> I was always wondering the rationale behind introducing
>> Ada.Real_Time.Timing_Events. The delay statement does the very same thing:
>>
>> with Ada.Real_Time; use Ada.Real_Time;
>> ...
>> Event : Time;
>> begin
>> ...
>> Put_Line ("Starting alarm ...");
>> Event := Clock + To_Time_Span (3.0);
>>
>> Put_Line ("Waiting for alarm ...");
>> delay until Event;
>> Put_Line ("ALARM!!");
>
> In this trivial example, a simple delay is probably all you need.
>
> However, consider a slightly different twist on the alarm example.
> Suppose you have a burglar alarm where if you trip the alarm
> you have 1 minute to correctly enter the security code, or
> the police are called. If you correctly enter the code in time
> the alarm is canceled. This gets you into the realm where
> the timing events package is more useful.
>
> You could accomplish this also using a task to monitor the timeout, but
> that could be considered a "heavier" approach depending on the
> implementation of the timing events package. Timing events provide a
> simpler abstraction, if all you want is an event to fire at sometime in
> the future. Plus if you have many such sort of events in a program, you
> could potentially save yourself from having to add tasks for each event
> you want to monitor, resulting in less system resources being used.
You must do it per a monitor task anyway. Your design is not scalable, and
the code is not conformant to Ada, because you are using potentially
blocking Put_Line within a protected action (in Call_Police).
When an alarm is triggered, that happens at the context of a protected
action. The protected action is quite limited to what you could do there.
That is only non-blocking and *very* short stuff. This means that you won't
be able to "call police" from there. You could set some flags, but you
could not initiate any "non-instant" action otherwise than by releasing a
task. Non-instant actions are for tasks. You need a task. If the key input
task gets blocked beyond reach of asynchronous transfer of control, which
is your case, because Ada does not require Text_IO abortable (yet
misleadingly provides an example of in RM (:-)), anyway, that means, you
inescapably need a second task.
-----------
Timing_Events does not have any advantages over delay or asynchronous
transfer of control. I guess it was provided for some low-level stuff like
interrupts from hardware timers. However there was already a support for
interrupts mapped into protected operations, so it really puzzles me why
Timing_Events were added.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2009-09-25 9:17 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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox