comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: ADA task
Date: 1996/09/13
Date: 1996-09-13T00:00:00+00:00	[thread overview]
Message-ID: <51cjp0$q7k@watnews1.watson.ibm.com> (raw)
In-Reply-To: 5174qu$o1p@nr1.ottawa.istar.net


In article <5174qu$o1p@nr1.ottawa.istar.net>, "Roumen Roupski"
<Roumen.Roupski@Pika.Ca> writes: 

|> 1. How can I implement a task running at regular intervals, for example
|> every 50ms +/- 5ms. The task activation must be guaranteed too.

By a "task", you seem to mean a piece of code to do certain work one
time. At regular intervals, the task is "run" to accomplish this work.

In Ada, a "task" is a thread of control, and the typical approach to
periodic processing is for this thread to remain in existence throughout
the program, executing a loop in which it spends most of its time
sleeping (thus not consuming CPU) and wakes up at the right times to do
its work: 

   task Cyclic_Processor;

   task body Cyclic_Processor is
      Next_Wakeup : Calendar.Time := Calendar.Clock;
      Interval    : constant Duration := 0.050;
   begin
      loop
         delay until Next_Wakeup;
         Do_Some_Work;
         Next_Wakeup := Next_Wakeup + Interval;
      end loop;
   end Cyclic_Processor;

The "delay until" statement is a new feature in Ada 95.  In Ada 83 you
would write

   delay Next_Wakeup - Calendar.Clock;

which delays for the specified amount of time (in this case, the time
from now until Next_Wakeup).

--
Norman H. Cohen    ncohen@watson.ibm.com




  parent reply	other threads:[~1996-09-13  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-11  0:00 ADA task Roumen Roupski
1996-09-12  0:00 ` Philip Brashear
1996-09-13  0:00 ` Norman H. Cohen [this message]
1996-09-13  0:00   ` Samuel T. Harris
1996-09-14  0:00     ` Robert Dewar
1996-09-14  0:00       ` Samuel T. Harris
1996-09-15  0:00         ` David C. Hoos, Sr.
1996-09-16  0:00           ` Samuel T. Harris
1996-09-16  0:00     ` Norman H. Cohen
1996-09-14  0:00   ` Ken Garlington
1996-09-14  0:00   ` Roumen Roupski
1996-09-16  0:00     ` Norman H. Cohen
1996-09-16  0:00   ` Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
1996-09-17  0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-19  0:00 ` Norman H. Cohen
1996-09-20  0:00   ` Robert A Duff
1996-09-17  0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-20  0:00 ` Robert A Duff
1996-09-18  0:00 tmoran
replies disabled

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