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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d0c649cbc04d397b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Weird problem with recursion and tasks Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1165116074.751484.99560@j44g2000cwa.googlegroups.com> Date: Sun, 3 Dec 2006 10:43:33 +0100 Message-ID: NNTP-Posting-Date: 03 Dec 2006 10:43:33 CET NNTP-Posting-Host: 6b280874.newsspool2.arcor-online.net X-Trace: DXC=G6PFA04d\MIAa;:RKVJ>LEA9EHlD;3YcB4Fo<]lROoRAFl8W>\BH3YBk\:0L\G_VLJDNcfSJ;bb[EIRnRBaCd On 2 Dec 2006 19:21:14 -0800, christopher.orihuela@gmail.com wrote: > 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. > �Could anybody tell me why for values of MaxI > 4 I allways get a > higer count of A in the following program? Thanks. It looks like a compiler bug to me (GNAT 3.15p, Windows). If we added a few put_lines: With Ada.Text_IO, Ada.Strings.Fixed; Use Ada.Text_IO, Ada.Strings.Fixed; Procedure My_Proc is protected type Counter is Procedure IncA; Procedure IncB; Procedure ShowCounts; private A, B: Natural := 0; end Counter; protected body Counter is Procedure IncA is begin A := A+1; end IncA; Procedure IncB is begin B := 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 >= MaxI) then return; end if; MyCounter.IncA; MyCounter.IncA; declare task My_Recursive_Task; task body My_Recursive_Task is begin Put_Line(I * " " & "Start task"); Recursive(I+1, MaxI); MyCounter.IncB; Put_Line(I * " " & "Stop task"); end My_Recursive_Task; begin Recursive(I+1, MaxI); MyCounter.IncB; end; end Recursive; begin Recursive (1, 5); MyCounter.ShowCounts; end My_Proc; we would see that starting with MaxI=4 and higher some of My_Recursive_Task are not awaited for termination by their masters, when the task object gets out of scope. I see it in breach with ARM 7.6.1(4). -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de