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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!postnews.google.com!q24g2000prf.googlegroups.com!not-for-mail From: Anh Vo Newsgroups: comp.lang.ada Subject: Re: Periodic tasks - organization Date: Fri, 18 Jul 2008 08:31:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2172d1a7-39a7-412c-9f30-635054f9103d@q24g2000prf.googlegroups.com> References: <86589099-2e4e-4b7d-ace0-6f1f864a3fa2@y21g2000hsf.googlegroups.com> <6e0jbhF4o43oU1@mid.individual.net> <561c8fa7-f26d-49a3-b54c-229c20462c04@r66g2000hsg.googlegroups.com> NNTP-Posting-Host: 209.225.224.254 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1216395090 32482 127.0.0.1 (18 Jul 2008 15:31:30 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 18 Jul 2008 15:31:30 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q24g2000prf.googlegroups.com; posting-host=209.225.224.254; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1; .NET CLR 3.0.04506.648),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:1210 Date: 2008-07-18T08:31:29-07:00 List-Id: On Jul 17, 12:31=A0pm, Simon Wright wrote: > Anh Vo writes: > > On Jul 16, 2:38=A0pm, Simon Wright wrote: > >> Anh Vo writes: > >> > It is even better to use periodic timers built on top > >> > Ada.Real_Time.Timing_Events. Then, explicit tasks are not needed. > > >> Only 'better' if that solution meets a need that's not met by the > >> straightforward approach. > > >> I see that Timing Event Handlers are meant to be executed directly by > >> the protected handler operation > >> (http://www.adaic.com/standards/05rm/html/RM-D-15.html25/2), so > >> clearly the intent is that some task should be released by the action > >> of the handler (similar to interrupts). So you still need explicit > >> tasks! just replacing a delay with a blocking wait on the PO which > >> will be triggered by the timing event -- a lot of complication. > > > Making two explicit tasks involves overhead for sure. It is true that > > using PO construct is more complex than using two independent tasks. > > Furthermore, an explicit task is not needed once the timer is started > > initially. > > But there are limits on what is permissible within a protected > procedure, are there not? > > Not sure what you mean by "once the timer is started initially", > timing events are one-shot (once the event fires, it's cleared). > > In the code below (my first try, excuse any stupidities & the need for > 'Unresricted_Access) I reckon there are 11 extra logical LOC ... > > with Ada.Real_Time.Timing_Events; > with Ada.Text_IO; use Ada.Text_IO; > > procedure Periodic is > > =A0 =A0protected Po is > =A0 =A0 =A0 procedure Handler (E : in out Ada.Real_Time.Timing_Events.Tim= ing_Event); > =A0 =A0 =A0 entry Wait; > =A0 =A0private > =A0 =A0 =A0 Released : Boolean :=3D False; > =A0 =A0end Po; > =A0 =A0protected body Po is > =A0 =A0 =A0 procedure Handler (E : in out Ada.Real_Time.Timing_Events.Tim= ing_Event) > =A0 =A0 =A0 is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Released :=3D True; > =A0 =A0 =A0 end Handler; > =A0 =A0 =A0 entry Wait when Released is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Released :=3D False; > =A0 =A0 =A0 end Wait; > =A0 =A0end Po; > > =A0 =A0Ev : Ada.Real_Time.Timing_Events.Timing_Event; > > =A0 =A0task T is end T; > =A0 =A0task body T is > =A0 =A0begin > =A0 =A0 =A0 Put_Line ("setting the Event"); > =A0 =A0 =A0 New_Line; > =A0 =A0 =A0 Ada.Real_Time.Timing_Events.Set_Handler > =A0 =A0 =A0 =A0 (Ev, > =A0 =A0 =A0 =A0 =A0In_Time =3D> Ada.Real_Time.To_Time_Span (1.0), > =A0 =A0 =A0 =A0 =A0Handler =3D> Po.Handler'Unrestricted_Access); > =A0 =A0 =A0 Po.Wait; > =A0 =A0 =A0 Put_Line ("t released."); > =A0 =A0end T; > > begin > =A0 =A0null; > end Periodic;- Hide quoted text - > > - Show quoted text - My design is completely different from yours. Indeed, an explicit task is not needed. See Gem #15, Timers, for details. http://www.adacore.com/2007/10/29/ada-gem-15/ A. Vo