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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,22ab316b1096e177 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!t13g2000yqm.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Tasks, Entries, and Variables of a Class-wide type Date: Mon, 1 Nov 2010 08:30:42 -0700 (PDT) Organization: http://groups.google.com Message-ID: <3dcee4c7-9753-41a1-8181-6e7e363bfbe8@t13g2000yqm.googlegroups.com> References: <7e77bb8f-17b6-4d51-9946-ea825f726682@f33g2000yqh.googlegroups.com> NNTP-Posting-Host: 174.28.254.71 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1288625442 29808 127.0.0.1 (1 Nov 2010 15:30:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 1 Nov 2010 15:30:42 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t13g2000yqm.googlegroups.com; posting-host=174.28.254.71; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729; .NET4.0E),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:16074 Date: 2010-11-01T08:30:42-07:00 List-Id: On Nov 1, 3:21=A0am, "Dmitry A. Kazakov" wrote: > On Sun, 31 Oct 2010 22:40:37 -0700 (PDT), Shark8 wrote: > > I=A2d originally wanted to have something like this: > > > Task Type Parser_Task is > > =A0Entry Parse( Input : in out String ) Return PostScript_Object=A2Clas= s; > > End Parser; > > This does not make sense, because it would parse during a rendezvous. Crap; you're right! While I certainly like the idea of having a task-construct within the language itself, I'm still quite new to using them in-practice. Thanks for pointing that out. > So > the effect on the caller would be same as if the caller would parse on it= s > own context. Why not to make parsing a plain function then? See above; programmer error due to not [fully] understanding the tool he's using. > > In order to take an advantage of tasking it should be like: > > task type Parser_Task is > =A0 =A0entry Request_Parsing (Input : String); > =A0 =A0entry Wait_For_Result (Output : out Post_Script_Object); > end Parser; > [SNIP] > > What you could do is to use the generic dispatching constructor (ARM 3.9)= . > Here is the outline: > > =A0 =A0package Parsers is > =A0 =A0 =A0 type Parser_Task; > =A0 =A0 =A0 type Post_Script_Object is tagged null record; > =A0 =A0 =A0 function Constructor (Parser : not null access Parser_Task) > =A0 =A0 =A0 =A0 =A0return Post_Script_Object; > =A0 =A0 =A0 task type Parser_Task is > =A0 =A0 =A0 =A0 =A0entry Request (Input : String); > =A0 =A0 =A0 =A0 =A0entry Wait_For_Result (Output : out Tag); > =A0 =A0 =A0 =A0 =A0entry Get_Result (Output : out Post_Script_Object'Clas= s); > =A0 =A0 =A0 end Parser_Task; > =A0 =A0 =A0 function Get_Object is > =A0 =A0 =A0 =A0 =A0new Ada.Tags.Generic_Dispatching_Constructor > =A0 =A0 =A0 =A0 =A0 =A0 =A0(Post_Script_Object, Parser_Task, Constructor)= ; > =A0 =A0end Parsers; > > The implementation: > > =A0 =A0package body Parsers is > =A0 =A0 =A0 function Constructor (Parser : not null access Parser_Task) > =A0 =A0 =A0 =A0 =A0return Post_Script_Object is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0return Result : Post_Script_Object do > =A0 =A0 =A0 =A0 =A0 =A0 Parser.Get_Result (Result); > =A0 =A0 =A0 =A0 =A0end return; > =A0 =A0 =A0 end Constructor; > > =A0 =A0 =A0 task body Parser_Task is > =A0 =A0 =A0 =A0 =A0Source : Unbounded_String; > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0loop > =A0 =A0 =A0 =A0 =A0 =A0 select > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0accept Request (Input : String) do > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Source :=3D To_Unbounded_String (Inpu= t); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end Request; > =A0 =A0 =A0 =A0 =A0 =A0 or terminate; > =A0 =A0 =A0 =A0 =A0 =A0 end select; > =A0 =A0 =A0 =A0 =A0 =A0 -- Here we parsing the stuff in Source. It will c= reate all > =A0 =A0 =A0 =A0 =A0 =A0 -- sorts of objects derived from Post_Script_Obje= ct. > =A0 =A0 =A0 =A0 =A0 =A0 -- For example: > =A0 =A0 =A0 =A0 =A0 =A0 declare > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Result : Post_Script_Object'Class :=3D > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Post_Script_Object'(null record); > =A0 =A0 =A0 =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0accept Wait_For_Result (Output : out Tag) = do > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Output :=3D Result'Tag; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end Wait_For_Result; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0accept Get_Result (Output : out Post_Scrip= t_Object'Class) do > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Output :=3D Result; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0end Get_Result; > =A0 =A0 =A0 =A0 =A0 =A0 end; > =A0 =A0 =A0 =A0 =A0end loop; > =A0 =A0 =A0 end Parser_Task; > =A0 =A0end Parsers; > > Note, you will need to override Constructor for each type derived from > Post_Script_Object. > > Here is how to use it on the client side: > > =A0 =A0Worker : aliased Parser_Task; > begin > =A0 =A0Worker.Request ("..."); > =A0 =A0declare > =A0 =A0 =A0 Result_Type : Tag; > =A0 =A0begin > =A0 =A0 =A0 Worker.Wait_For_Result (Result); -- Now we know the type > =A0 =A0 =A0 declare > =A0 =A0 =A0 =A0 =A0Object : Post_Script_Object'Class :=3D > =A0 =A0 =A0 =A0 =A0 =A0 Get_Object Result_Type, Worker'Access); > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0-- Doing something with object; > =A0 =A0 =A0 end; > =A0 =A0end; Ah... I get it. By putting the actual parsing between ACCEPT statements you're allowing the structure within the task from encountering the problem of multiple tasks with one calling Wait_for_Object after another [different task] had called Request which could/would have happened if you had something like: Task body .... Working_Text : Unbounded_String; Temporary_Object : Access PostScript_Object'Class; --- Just a holder for the operations... .... begin loop Select Accept Request(Input_String : In String) do Working_Test:=3D To_Unbounded_String( Input_String ); end Request; OR Accept Wait_For_Object( Output : out Tag ) do Output:=3D Temporary_Object'Tag; end Wait_For_Object; OR Get_Result( Output : out PostScript_Object'Class ) do Output:=3D Temporary_Object; end Wait_For_Object; End Select; end loop; end; Which, sad to admit, was how I was thinking it would have to be done. WAAAAY over-complicated [because it would need some state-variables and blocking-logic] compared to the solution you presented. So, thank you again for the insight/learning.