comp.lang.ada
 help / color / mirror / Atom feed
From: Anh Vo <anhvofrcaus@gmail.com>
Subject: Re: Abortable Timed Action
Date: Wed, 6 Jan 2016 13:14:14 -0800 (PST)
Date: 2016-01-06T13:14:14-08:00	[thread overview]
Message-ID: <f48a91a2-7d72-4dc4-b219-4a02b1efe237@googlegroups.com> (raw)
In-Reply-To: <n63r0n$12il$1@adenine.netfront.net>

On Thursday, December 31, 2015 at 10:09:30 AM UTC-8, T.G. wrote:
> On 2015-12-31, Anh Vo <anhvofrcaus@gmail.com> wrote:
> > I think accuracy more important than better/simpler way. There is a
> > drifting issue in your codes in term of time since delay statement
> > is involved. In addition, timer has no problem of this kind. If you
> > decide to use timer, take look at
> > http://www.adacore.com/adaanswers/gems/ada-gem-15/. Let me know if
> > have any question.
> >
> > Anh Vo
> 
> Very nice example. I didn't know about Ada.Real_Time.Timing_Events,
> I'll probably go with that. Thanks for the pointer.

After looking at your original post again, I believe your code should work after replacing delay statement by delay until statement. The delay until statement does not have time drifting issue. In addition, then Entry Finish can be replaced by the terminate alternative. The modified version is shown below.

   with Ada.Calendar; use type Ada.Calendar.Time;
   with Ada.Text_Io;  use Ada.Text_Io;
   -- ...

   -- ...
   task type Timed_Action_Task is 
     entry Exec_After (T : Duration); 
     entry Cancel; 
   end Timed_Action_Task; 

   task body Timed_Action_Task is 
      Timeout : Duration; 
   begin 
      loop 
         select 
            accept Exec_After (T : Duration) do 
               Timeout := T; 
            end Exec_After; 
            select 
               accept Cancel; 
            or 
               delay until (Ada.Calendar.Clock + Timeout); 
               Put_Line ("Do Something"); 
            end select; 
         or 
            terminate;
         end select; 
      end loop; 
   end Timed_Action_Task;

  reply	other threads:[~2016-01-06 21:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-31  4:15 Abortable Timed Action T.G.
2015-12-31  6:40 ` Anh Vo
2015-12-31  7:32   ` T.G.
2015-12-31 16:21     ` Anh Vo
2015-12-31 18:09       ` T.G.
2016-01-06 21:14         ` Anh Vo [this message]
2016-01-08 20:24           ` T.G.
2016-01-09  8:45             ` Simon Wright
2016-01-09  9:10               ` Dmitry A. Kazakov
2016-01-09 14:41               ` Bob Duff
2016-01-09 15:59               ` T.G.
replies disabled

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