comp.lang.ada
 help / color / mirror / Atom feed
From: William FRANCK <william.franck@free.fr>
Subject: Re: How to transfer Class-Wide object to a Task ?
Date: Mon, 14 Oct 2019 22:21:48 +0200
Date: 2019-10-14T22:21:48+02:00	[thread overview]
Message-ID: <5da4d8dc$0$20339$426a74cc@news.free.fr> (raw)
In-Reply-To: 5da4cf81$0$20312$426a74cc@news.free.fr

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;

  parent reply	other threads:[~2019-10-14 20:21 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14 19:41 How to transfer Class-Wide object to a Task ? William FRANCK
2019-10-14 19:55 ` Shark8
2019-10-14 20:48   ` William FRANCK
2019-10-14 22:01     ` Shark8
2019-10-15  5:13       ` William FRANCK
2019-10-14 19:58 ` Dmitry A. Kazakov
2019-10-14 20:58   ` William FRANCK
2019-10-15  4:40     ` Per Sandberg
2019-10-15  5:40       ` William FRANCK
2019-10-16 20:04       ` William FRANCK
2019-10-16 23:43         ` Anh Vo
2019-10-17  9:28         ` William FRANCK
2019-10-17 10:00           ` Dmitry A. Kazakov
2019-10-17 10:45             ` William FRANCK
2019-10-15  7:21     ` Dmitry A. Kazakov
2019-10-15 14:31       ` Optikos
2019-10-15 19:41         ` William FRANCK
2019-10-15 20:03           ` Shark8
2019-10-14 20:21 ` William FRANCK [this message]
2019-10-14 20:32   ` Dmitry A. Kazakov
2019-10-14 21:04     ` William FRANCK
2019-10-14 21:57   ` Shark8
2019-10-15  5:43     ` William FRANCK
replies disabled

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