This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug ada/30078] New: problems mixing Tasks and recursion


The attached file contains a procedure that shows weird problems mixing tasks
and recursion.
A correct program behavior would be showing the same number of As and Bs, but
instead, for values of IMax > 4 we get different counts.

gcc version 3.4.6 for GNAT GPL 2006 (20060522) running on windows 2000/WinXP
gcc version 3.4.6 for GNAT GPL 2006 (20060522) running on linux/CentOS.



With Ada.Text_IO;
Use Ada.Text_IO;

Procedure My_Proc is

   protected type Counter is
      Procedure IncA;
      Procedure IncB;
      function GetA return Natural;
      function GetB return Natural;
   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;
      function GetA return Natural is
      begin
         return A;
      end GetA;
      function GetB return Natural is
      begin
         return B;
      end GetB;
   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;
         exception
            when Others =>
               Put_Line ("Exception");
         end My_Recursive_Task;

      begin
         Recursive(I+1, MaxI);
         MyCounter.IncB;
      exception
         when Others =>
            Put_Line ("Exception");
      end;
   end Recursive;

begin
   Recursive (1, 6);
   Put_Line("A: " & Integer'Image(MyCounter.GetA));
   Put_Line("B: " & Integer'Image(MyCounter.GetB));
end My_Proc;


-- 
           Summary: problems mixing Tasks and recursion
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: orihuela at idecnet dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30078


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]