comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@maps.futureapps.de>
Subject: Re: coroutines (Maping of Ada tasks on the plateforme OS threads model)
Date: Tue, 30 Jun 2009 00:45:38 +0200
Date: 2009-06-30T00:45:37+02:00	[thread overview]
Message-ID: <4a494411$0$31879$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <073575da-8319-4b6a-a41f-a03c736ebad6@37g2000yqp.googlegroups.com>

Hibou57 (Yannick Duch�ne) wrote:

> By the ways, I'm looking for the best way to do coroutines with Ada,
> without tasking (none-recursive coroutines, so no separate stack is
> needed, just global storage for local variables). Yes, this can be
> achieved with a select/when statement and a state enumeration, but
> this way is not very clean nor nice.

Not necessarily the best, or even a good way, the
following is an outline. (Yes, there is recursion BTW,
but it isn't crucial.)

procedure News32 is

   Max_Statements: constant := 10;
   type Statement_Index is range 1 .. Max_Statements;

   A_Index,
   B_Index : Statement_Index;

   procedure A;
   procedure B;

   Waiting: Boolean;
   Result: Integer;

   procedure A is
   begin
      case A_Index is
         when 1 => goto STMT1;
         when 2 => goto STMT2;
         when others => raise Program_Error;
      end case;

      <<STMT1>>
      if Waiting then
         B;
         return;
      end if;
      Result := 1;

      <<STMT2>>
      Result := 2;

   end A;

   procedure B is
   begin
      case B_Index is
         when 1 => goto STMT1;
         when others => raise Program_Error;
      end case;

      <<STMT1>>
      A_Index := A_Index + 1;
      A;  -- resumes A at A.STMT2
   end B;

begin
   Result := 0;
   Waiting := True;
   A_Index := 1;
   B_Index := 1;
   A;
   pragma Assert(Result = 2);
end News32;



      reply	other threads:[~2009-06-29 22:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-28  0:35 Maping of Ada tasks on the plateforme OS threads model Hibou57 (Yannick Duchêne)
2009-06-28 16:31 ` sjw
2009-06-29 20:56   ` Hibou57 (Yannick Duchêne)
2009-06-29 22:45     ` Georg Bauhaus [this message]
replies disabled

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