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!fdn.fr!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp3-1.free.fr!not-for-mail From: William FRANCK Newsgroups: comp.lang.ada Date: Mon, 14 Oct 2019 22:58:42 +0200 Message-ID: <5da4e182$0$20321$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:58:42 CEST NNTP-Posting-Host: 92.184.99.238 X-Trace: 1571086722 news-1.free.fr 20321 92.184.99.238:35700 X-Complaints-To: abuse@proxad.net Xref: reader01.eternal-september.org comp.lang.ada:57283 Date: 2019-10-14T22:58:42+02:00 List-Id: On 2019-10-14 19:58:34 +0000, Dmitry A. Kazakov said: > On 2019-10-14 21:41, William FRANCK wrote: > >> 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. > > Strange design, why not to pipe streams using a FIFO? > >> 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 ...) > > Yes, if using FIFO, a protected object can be used to signal > non-empty/not-full events at the FIFO ends. > > Otherwise, use a reference-counted handle or a plain access type to the > target object. The reader task allocates the object in the pool and > passes a handle or access to it to the writer. The writer task writes > the object and then disposes it. Thanks you Dimitry for your follow-up. Here is the multitasking part (simplified) (working, no issue) for reading the datafile, and writing it back (after some data-process) My first intention was : while Writing.Bloc is busy writing on the output file, Reading.Bloc can take 1 record in advance Now I have to insert the class-wide object passing in the Bloc. As You mentionned, should I use a protected type (FIFO) instead of 2 // tasks ? --================ with Ada.Text_io; procedure main_tasks is task reading is entry Open; entry Bloc; entry Stop; end reading; task writing is entry Create; entry Bloc; entry Stop; end writing; task body reading is begin loop select accept Open; Ada.Text_IO.put_line("Opening file ..."); or accept Bloc do Ada.Text_IO.put_line("Reading ..."); end Bloc; or accept Stop; Ada.Text_IO.put_line("Reading Stopped !"); exit; end select; end loop; end reading; task body writing is begin loop select accept Create; Ada.Text_IO.put_line("Creating file ..."); or accept Bloc do Ada.Text_IO.put_line("Got bloc !"); end Bloc; Ada.Text_IO.put_line("Writing bloc ..."); or accept Stop; Ada.Text_IO.put_line("Writing Stopped !"); exit; end select; end loop; end writing; begin Writing.Create; Reading.Open; for i in 1..10 loop -- While not end_of_file() Reading.Bloc; Writing.Bloc; end loop; Reading.Stop; Writing.Stop; end main_tasks;