comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Periodic tasks - organization
Date: Sun, 13 Jul 2008 14:47:53 -0700 (PDT)
Date: 2008-07-13T14:47:53-07:00	[thread overview]
Message-ID: <86589099-2e4e-4b7d-ace0-6f1f864a3fa2@y21g2000hsf.googlegroups.com> (raw)

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?

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com



             reply	other threads:[~2008-07-13 21:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-13 21:47 Maciej Sobczak [this message]
2008-07-13 23:35 ` Periodic tasks - organization tmoran
2008-07-14  3:52 ` george.priv
2008-07-14  9:08 ` Alex R. Mosteo
2008-07-14 15:31   ` Anh Vo
2008-07-16 21:38     ` Simon Wright
2008-07-16 22:47       ` Anh Vo
2008-07-17 19:31         ` Simon Wright
2008-07-18 15:31           ` Anh Vo
2008-07-18 16:22             ` Dmitry A. Kazakov
2008-07-19  1:37               ` Anh Vo
2008-07-19 10:22                 ` Dmitry A. Kazakov
2008-07-20  9:46               ` Simon Wright
replies disabled

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