From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Weird problem with recursion and tasks
Date: Sun, 3 Dec 2006 10:43:33 +0100
Date: 2006-12-03T10:43:33+01:00 [thread overview]
Message-ID: <almtzna7896n.1r4xuyjpsu3hn.dlg@40tude.net> (raw)
In-Reply-To: 1165116074.751484.99560@j44g2000cwa.googlegroups.com
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
next prev parent reply other threads:[~2006-12-03 9:43 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-03 3:21 Weird problem with recursion and tasks christopher.orihuela
2006-12-03 8:34 ` Gautier
2006-12-03 9:43 ` Dmitry A. Kazakov [this message]
2006-12-03 13:56 ` Matthew Heaney
2006-12-05 0:50 ` Craig Carey <research@ijs.co.nz>
2006-12-03 21:10 ` christopher.orihuela
2006-12-04 20:09 ` christopher.orihuela
2006-12-05 11:38 ` Georg Bauhaus
2006-12-05 13:07 ` Dmitry A. Kazakov
2006-12-05 12:03 ` Ludovic Brenta
2006-12-05 12:24 ` Georg Bauhaus
2006-12-05 13:00 ` Ludovic Brenta
2006-12-05 20:37 ` christopher.orihuela
2006-12-05 22:16 ` christopher.orihuela
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox