comp.lang.ada
 help / color / mirror / Atom feed
* Weird problem with recursion and tasks
@ 2006-12-03  3:21 christopher.orihuela
  2006-12-03  8:34 ` Gautier
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: christopher.orihuela @ 2006-12-03  3:21 UTC (permalink / raw)


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.


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 := 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
            Recursive(I+1, MaxI);
            MyCounter.IncB;
         end My_Recursive_Task;

      begin
         Recursive(I+1, MaxI);
         MyCounter.IncB;
      end;
   end Recursive;
   
begin
   Recursive (1, 6);
   MyCounter.ShowCounts;
end My_Proc;




^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2006-12-05 22:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox