comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon.j.wright@mac.com>
Subject: Re: Periodic tasks - organization
Date: Thu, 17 Jul 2008 20:31:11 +0100
Date: 2008-07-17T20:31:11+01:00	[thread overview]
Message-ID: <m2ej5se29s.fsf@mac.com> (raw)
In-Reply-To: e5e7d089-7e6d-4632-acbc-a81936ff489d@79g2000hsk.googlegroups.com

Anh Vo <anhvofrcaus@gmail.com> writes:

> On Jul 16, 2:38�pm, Simon Wright <simon.j.wri...@mac.com> wrote:
>> Anh Vo <anhvofrc...@gmail.com> writes:
>> > It is even better to use periodic timers built on top
>> > Ada.Real_Time.Timing_Events. Then, explicit tasks are not needed.
>>
>> Only 'better' if that solution meets a need that's not met by the
>> straightforward approach.
>>
>> I see that Timing Event Handlers are meant to be executed directly by
>> the protected handler operation
>> (http://www.adaic.com/standards/05rm/html/RM-D-15.html25/2), so
>> clearly the intent is that some task should be released by the action
>> of the handler (similar to interrupts). So you still need explicit
>> tasks! just replacing a delay with a blocking wait on the PO which
>> will be triggered by the timing event -- a lot of complication.
>
> Making two explicit tasks involves overhead for sure. It is true that
> using PO construct is more complex than using two independent tasks.
> Furthermore, an explicit task is not needed once the timer is started
> initially.

But there are limits on what is permissible within a protected
procedure, are there not?

Not sure what you mean by "once the timer is started initially",
timing events are one-shot (once the event fires, it's cleared).

In the code below (my first try, excuse any stupidities & the need for
'Unresricted_Access) I reckon there are 11 extra logical LOC ...

with Ada.Real_Time.Timing_Events;
with Ada.Text_IO; use Ada.Text_IO;

procedure Periodic is
      
   protected Po is 
      procedure Handler (E : in out Ada.Real_Time.Timing_Events.Timing_Event);
      entry Wait;
   private
      Released : Boolean := False;
   end Po;
   protected body Po is
      procedure Handler (E : in out Ada.Real_Time.Timing_Events.Timing_Event)
      is
      begin
	 Released := True;
      end Handler;
      entry Wait when Released is
      begin
	 Released := False;
      end Wait;
   end Po;
      
   Ev : Ada.Real_Time.Timing_Events.Timing_Event;
   
   task T is end T;
   task body T is
   begin
      Put_Line ("setting the Event");
      New_Line;
      Ada.Real_Time.Timing_Events.Set_Handler 
	(Ev,
	 In_Time => Ada.Real_Time.To_Time_Span (1.0),
	 Handler => Po.Handler'Unrestricted_Access);
      Po.Wait;
      Put_Line ("t released.");
   end T;
   
begin
   null;
end Periodic;



  reply	other threads:[~2008-07-17 19:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-13 21:47 Periodic tasks - organization Maciej Sobczak
2008-07-13 23:35 ` tmoran
2008-07-14  3:52 ` george.priv
2008-07-14  9:08 ` Alex R. Mosteo
2008-07-14 15:31   ` Anh Vo
2008-07-16 21:38     ` Simon Wright
2008-07-16 22:47       ` Anh Vo
2008-07-17 19:31         ` Simon Wright [this message]
2008-07-18 15:31           ` Anh Vo
2008-07-18 16:22             ` Dmitry A. Kazakov
2008-07-19  1:37               ` Anh Vo
2008-07-19 10:22                 ` Dmitry A. Kazakov
2008-07-20  9:46               ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox