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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed3-b.proxad.net!nnrp3-1.free.fr!not-for-mail From: William FRANCK Newsgroups: comp.lang.ada Date: Mon, 14 Oct 2019 22:21:48 +0200 Message-ID: <5da4d8dc$0$20339$426a74cc@news.free.fr> References: <5da4cf81$0$20312$426a74cc@news.free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: How to transfer Class-Wide object to a Task ? User-Agent: Unison/2.2 Organization: Guest of ProXad - France NNTP-Posting-Date: 14 Oct 2019 22:21:48 CEST NNTP-Posting-Host: 92.184.98.78 X-Trace: 1571084508 news-1.free.fr 20339 92.184.98.78:45937 X-Complaints-To: abuse@proxad.net Xref: reader01.eternal-september.org comp.lang.ada:57280 Date: 2019-10-14T22:21:48+02:00 List-Id: On 2019-10-14 19:41:53 +0000, William FRANCK said: > Hey all ! > Here is a nice issue I have with Ada (GNAT 2012) when trying to do OO > dispatching with streams in different tasks ... > > Here it is : > I'd like to get from a task RdV (Entry-Access) an object which could be > any subclass of a root'Class, and pass it to another task > > Context : read (Root'Class'Input() ) tagged records from an input > stream, and send them to anther task which will write > (Root'Class'Output() ) the given records to another output stream. > > I'm stuck with task memory isolation with does NOT allow to pass any > access object to a Root'Class. > > Should I try to use a protected object ? > (not shore this solves the passing of a Class-wide object ...) > > Thanks for your feed-back, > William Here is some code to illustrate (code needs soem fixings) with Ada.Text_io; procedure main_ClassWide_to_2Task is type Geo2D is tagged record Y, X : integer; Name : String(1..6) := "Object"; end record; type Circle is new Geo2D with record Radius : integer; end record; myObject : access Geo2D'Class; -- ============================== task reading is entry Object(This : in out Geo2D'Class); entry Stop; end reading; task writing is entry Object(This : in Geo2D'Class); entry Stop; end writing; -- ============================== task body reading is O2D : access Geo2D'Class; begin loop select accept Object(This : in out Geo2D'Class); declare -- (shortcut to simulate real case) :: Object : constant Geo2D'Class := Dispatching_Input (Ada.Tags.Internal_Tag (External_Tag), Stream); begin O2D := new Circle'(0,0,"Cercle",10); Ada.Text_io.Put_line("Reading 2D Object: " & O2D.Name); -- debug trace -- This.all := O2D.all; --Compiler error : "This" is undefined end; or accept Stop; exit; end select; end loop; end reading; -- ============================== task body writing is myObject : access Geo2D'Class; begin loop select accept Object(This : in Geo2D'Class) do myObject := This'Access; end Object; Ada.Text_io.Put_line("Writing 2D Object: " & This.Name); -- debug trace or accept Stop; exit; end select; end loop; end writing; -- ============================== begin reading.Object(myObject.all); writing.Object(myObject.all); reading.Stop; writing.Stop; end main_ClassWide_to_2Task;