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: 103376,d0c649cbc04d397b,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!j44g2000cwa.googlegroups.com!not-for-mail From: "christopher.orihuela@gmail.com" Newsgroups: comp.lang.ada Subject: Weird problem with recursion and tasks Date: 2 Dec 2006 19:21:14 -0800 Organization: http://groups.google.com Message-ID: <1165116074.751484.99560@j44g2000cwa.googlegroups.com> NNTP-Posting-Host: 212.64.162.149 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1165116080 32317 127.0.0.1 (3 Dec 2006 03:21:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 3 Dec 2006 03:21:20 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: j44g2000cwa.googlegroups.com; posting-host=212.64.162.149; posting-account=LSWB7gwAAADdhkmUh3B46NY2ztMkCw_0 Xref: g2news2.google.com comp.lang.ada:7791 Date: 2006-12-02T19:21:14-08:00 List-Id: I was implementing a concurrent version of QuickSort (each half in a different task) when I realized that sometimes the recursive task didn't execute. =BFCould anybody tell me why for values of MaxI > 4 I allways get a higer count of A in the following program? Thanks. With Ada.Text_IO; Use Ada.Text_IO; Procedure My_Proc is protected type Counter is Procedure IncA; Procedure IncB; Procedure ShowCounts; private A, B: Natural :=3D 0; end Counter; protected body Counter is Procedure IncA is begin A :=3D A+1; end IncA; Procedure IncB is begin B :=3D B+1; end IncB; Procedure ShowCounts is begin Put_Line("A: " & Integer'Image(A)); Put_Line("B: " & Integer'Image(B)); end ShowCounts; end Counter; MyCounter : Counter; Procedure Recursive (I : Natural; MaxI : Natural) is begin if (I >=3D MaxI) then return; end if; MyCounter.IncA; MyCounter.IncA; declare Task My_Recursive_Task; Task Body My_Recursive_Task is begin Recursive(I+1, MaxI); MyCounter.IncB; end My_Recursive_Task; begin Recursive(I+1, MaxI); MyCounter.IncB; end; end Recursive; =20 begin Recursive (1, 6); MyCounter.ShowCounts; end My_Proc;