comp.lang.ada
 help / color / mirror / Atom feed
From: "christopher.orihuela@gmail.com" <christopher.orihuela@gmail.com>
Subject: Weird problem with recursion and tasks
Date: 2 Dec 2006 19:21:14 -0800
Date: 2006-12-02T19:21:14-08:00	[thread overview]
Message-ID: <1165116074.751484.99560@j44g2000cwa.googlegroups.com> (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;




             reply	other threads:[~2006-12-03  3:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-03  3:21 christopher.orihuela [this message]
2006-12-03  8:34 ` Weird problem with recursion and tasks 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
replies disabled

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