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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1356f4179c1e4ef4 X-Google-Attributes: gid103376,public From: ncohen@watson.ibm.com (Norman H. Cohen) Subject: Re: ADA task Date: 1996/09/13 Message-ID: <51cjp0$q7k@watnews1.watson.ibm.com>#1/1 X-Deja-AN: 180456492 distribution: world references: <5174qu$o1p@nr1.ottawa.istar.net> organization: IBM T.J. Watson Research Center reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada Date: 1996-09-13T00:00:00+00:00 List-Id: In article <5174qu$o1p@nr1.ottawa.istar.net>, "Roumen Roupski" 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