comp.lang.ada
 help / color / mirror / Atom feed
From: "Vo, Anh \(US SSA\)" <anh.vo@baesystems.com>
To: "Rolf" <rolf.ebert_nospam_@gmx.net>, <comp.lang.ada@ada-france.org>
Subject: RE: Timing events in GNAT GPL 2006
Date: Fri, 12 Jan 2007 09:40:19 -0800
Date: 2007-01-12T20:25:02+01:00	[thread overview]
Message-ID: <mailman.18.1168629618.18371.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <1168620554.469932.313660@a75g2000cwd.googlegroups.com>

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

procedure Test_Timing_Event is

   protected Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event);
   end Clock_Tick;

   Tick    : Timing_Event;
   One_Sec : constant Time_Span := Seconds (1);

   protected body Clock_Tick is
      procedure Inc_Clock (Ev : Timing_Event)
      is
      begin
         Put_Line ("Inc_Sec");
         -- using Time_Span
         Set_Handler (Tick, One_Sec, Handler => Inc_Clock'Access);
      end Inc_Clock;
   end Clock_Tick;

begin
   -- using absolute time
   Set_Handler (Tick, Clock + One_Sec, Clock_Tick.Inc_Clock'Access);
   loop null; end loop;
end Test_Timing_Event;

-- >>

There are three things wrong with your codes. Two of them are critical.
1. The protected procedure Inc_Clock has wrong parameter mode. It must
be in out mode.
2. The call Set_Handler from the protected procedure will result in a
deadlock it is run.
3. Protected object must be declared at the library level. Yours is not.
As the result, non-local pointer cannot point to local object error at
lines 20 and 26

I designed for both one shot and periodic timers using Timing Event. If
it is helpful, I will post my code here. Just let me know.

AV



      reply	other threads:[~2007-01-12 17:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-12 16:49 Timing events in GNAT GPL 2006 Rolf
2007-01-12 17:40 ` Vo, Anh (US SSA) [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