From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Abortable Timed Action
Date: Sat, 9 Jan 2016 10:10:08 +0100
Date: 2016-01-09T10:10:08+01:00 [thread overview]
Message-ID: <n6qipq$1q6i$1@gioia.aioe.org> (raw)
In-Reply-To: ly37u7p2dd.fsf@pushface.org
On 2016-01-09 09:45, Simon Wright wrote:
> "T.G." <anon@anon.org> writes:
>
>> delay until is an interesting idea. I'm assuming that time drift would
>> be an issue in periodic actions that repeat at a certain interval, but
>> in that case delay until could also have issues if it loses some
>> accuracy on each iteration.
Yes, if the period is not a multiple of the clock and system timer
interrupt source. Though there is no way to eliminate this type of
jitter, so why worry?
The resolution of Time (not accuracy) can be a problem, e.g. in the
suggested schema below, which will accumulate error. The error can be
compensated by computing Next as
Count := Count + 1;
Next :=
Start + Duration (Long_Float (Count) * Long_Float (Interval));
Though, it is difficult to imagine a scenario where that would be really
needed.
> The common solution is something like
>
> with Ada.Calendar;
> with Ada.Text_IO; use Ada.Text_IO;
> procedure Delay_Until is
> task T is
> entry Exec_After (T : Duration);
> end T;
> task body T is
> Start : Ada.Calendar.Time;
> Next : Ada.Calendar.Time;
> Interval : Duration;
> use type Ada.Calendar.Time;
> begin
> accept Exec_After (T : Duration) do
> Start := Ada.Calendar.Clock;
> Next := Start + T;
> Interval := T;
> end Exec_After;
> loop
> delay until Next;
> Next := Next + Interval; -- *not* Ada.Calendar.Clock + Interval
An missing ticks detection and compensation:
if Next < Clock then
Next := Clock;
Put_Line ("Ticks missed!");
end if;
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2016-01-09 9:10 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
2016-01-08 20:24 ` T.G.
2016-01-09 8:45 ` Simon Wright
2016-01-09 9:10 ` Dmitry A. Kazakov [this message]
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