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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,470e89e7a6575920 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: Periodic tasks - organization Date: Mon, 14 Jul 2008 11:08:33 +0200 Message-ID: <6e0jbhF4o43oU1@mid.individual.net> References: <86589099-2e4e-4b7d-ace0-6f1f864a3fa2@y21g2000hsf.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: individual.net OTRIe8gd2aGKrIeVcUy5iAC/MomuoJAFBWAAOGGHoIXFaxOn8= Cancel-Lock: sha1:Pw+t6aT4k3wgJbDMxwUzEYB6BtA= User-Agent: KNode/0.10.9 Xref: g2news1.google.com comp.lang.ada:1145 Date: 2008-07-14T11:08:33+02:00 List-Id: Maciej Sobczak wrote: > Consider a program that has a couple of periodic tasks. Let's say > there are two tasks, one with a period of 3s and another with a period > of 4s. Let's say that exact triggering is not required. > > The simplest way to do it is to just have appropriate delay statements > in main loops of these tasks. The advantage of such a setup is that > the tasks are completely self-contained and independent on any other > program entity. The disadvantage is that they are bound to the way > their periodicity is implemented. > > Another way is to have additional task that will serve as a clock, > "ticking" two protected objects that are countdown counters with > single entry that waits for the counter to reach zero. In this case > the tick would be 1s, as the greatest common divisor of two periods. > The working tasks can then wait on respective entries in these > protected objects, which are released when the counters reach zero. > The advantage of this approach is that the notion of time is extracted > from the working tasks themselves and can be easily changed to > something else, like waiting on a different kind of clock or an > interrupts or whatever without disturbing main working tasks. The > disadvantage is that there are more program entities (+ two protected > countdowns + 1 ticking task) to handle. > > What can you say about these two approaches? Which would you recommend > and when? I would use "delay until", which prevents any drift and still avoids using extra machinery.