From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Abortable Timed Action Date: Sat, 9 Jan 2016 10:10:08 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <446ae62f-6b95-4a4f-b253-85af071b6bf6@googlegroups.com> NNTP-Posting-Host: LNA1TkTuMxfwTHzeJdi6nA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:29063 Date: 2016-01-09T10:10:08+01:00 List-Id: On 2016-01-09 09:45, Simon Wright wrote: > "T.G." 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