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-Thread: a07f3367d7,5cc10500d0b7a280 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!f20g2000prn.googlegroups.com!not-for-mail From: Anh Vo Newsgroups: comp.lang.ada Subject: Re: task model Date: Thu, 15 Oct 2009 12:15:56 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6b6bd661-06b0-4ef6-8d48-0ef97d55fdd4@f20g2000prn.googlegroups.com> References: <04458a0b-1e58-478b-a2f0-c47226f840ac@f16g2000yqm.googlegroups.com> NNTP-Posting-Host: 149.32.224.34 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1255634156 28179 127.0.0.1 (15 Oct 2009 19:15:56 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 15 Oct 2009 19:15:56 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: f20g2000prn.googlegroups.com; posting-host=149.32.224.34; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; .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: g2news2.google.com comp.lang.ada:8703 Date: 2009-10-15T12:15:56-07:00 List-Id: On Oct 15, 11:00=A0am, Ludovic Brenta wrote: > Michael Tabak wrote on comp.lang.ada: > > > I'm prototyping some tasking with multiple accepts, the code is as > > follows: > > > with Ada.Text_Io; > > use Ada.Text_Io; > > > procedure task_test is > > > =A0 =A0procedure Process_Primary(node: in Integer) is > > > =A0 =A0begin > > > =A0 =A0 =A0 =A0Put_Line("This is number" & Integer'Image(node)); > > > =A0 =A0end Process_Primary; > > > =A0 =A0task proc1 is > > =A0 =A0 =A0entry process1(node : Integer); > > =A0 =A0 =A0entry continue; > > =A0 =A0end proc1; > > > =A0 =A0task body proc1 is > > =A0 =A0begin > > > =A0 =A0 =A0accept process1( node : Integer) do > > > =A0 =A0 =A0 =A0Process_Primary( node ); > > > =A0 =A0 =A0end; > > > =A0 =A0 =A0accept continue do > > =A0 =A0 =A0 =A0Put_Line("Called Continue task1"); > > =A0 =A0 =A0end; > > > =A0 =A0end proc1; > > > =A0 =A0task proc2 is > > =A0 =A0 =A0entry process2(node : Integer); > > =A0 =A0 =A0entry continue; > > =A0 =A0end proc2; > > > =A0 =A0task body proc2 is > > =A0 =A0begin > > > =A0 =A0 =A0accept process2( node : Integer) do > > > =A0 =A0 =A0 =A0 =A0Process_Primary( node ); > > > =A0 =A0 =A0end; > > > =A0 =A0 =A0accept continue do > > =A0 =A0 =A0 =A0Put_Line("Called Continue task2"); > > =A0 =A0 =A0end; > > > =A0 =A0end proc2; > > > begin > > =A0 for i in 1..2 loop > > =A0 =A0proc1.process1(1); > > =A0 =A0proc2.process2(2); > > =A0 =A0proc1.continue; > > =A0 =A0proc2.continue; > > =A0 end loop; > > end task_test; > > -----------------------------------------------------------------------= ----=AD------------------------------------------ > > > I get the out put I expect: > > > This is number 1 > > This is number 2 > > Called Continue task1 > > Called Continue task2 > > > But I also get the following error which I can't track down: > > > raised TASKING_ERROR : s-tasren.adb:486 > > Your expectations are wrong :) > > Your environment task contains a loop calling each task four times: > for each task the call sequence is processN, continue, processN, > continue. =A0But the tasks do not contain a loop, so they can accept > only the first two entry calls and then they terminate. =A0So the second > call to process1 raises Tasking_Error because task1 has terminated by > now. I would like to expand Ludovic's comment. You have a couple of options to improve it. 1. Make sure the task not terminated before calling its entry. That is using proc1'terminated syntax to query it. 2. Add infinite loop enclosing accept statements. So, entry call can be served always. This makes tasks alive even after the program ends (program will hang) unless Ctrl-C or other mean to end it. The clean solution is add entry Shutdown to the task. When this entry is invoked, just exit the loop. Thus, the task will terminate cleanly. Anh Vo