From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,33e2ff06dc7f500c X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 30 Jun 2009 00:45:38 +0200 From: Georg Bauhaus Reply-To: rm.tsoh+bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: coroutines (Maping of Ada tasks on the plateforme OS threads model) References: <31491d36-18ec-4da4-b1a6-1914d0867492@b14g2000yqd.googlegroups.com> <2b0f1f6b-51b2-45be-bcd9-85f2d6a389d9@t13g2000yqt.googlegroups.com> <073575da-8319-4b6a-a41f-a03c736ebad6@37g2000yqp.googlegroups.com> In-Reply-To: <073575da-8319-4b6a-a41f-a03c736ebad6@37g2000yqp.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <4a494411$0$31879$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 30 Jun 2009 00:45:37 CEST NNTP-Posting-Host: 6845b14f.newsspool3.arcor-online.net X-Trace: DXC=92G;gcCSXjMlU`@c^jLCbJMcF=Q^Z^V3H4Fo<]lROoRA^YC2XCjHcbIL9LV2A9OikEA:ho7QcPOVCed5V2gRG2;F:>T>L\nVV3J X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:6741 Date: 2009-06-30T00:45:37+02:00 List-Id: 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; <> if Waiting then B; return; end if; Result := 1; <> Result := 2; end A; procedure B is begin case B_Index is when 1 => goto STMT1; when others => raise Program_Error; end case; <> 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;