From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: Protected Type compiler complaint
Date: Tue, 08 Jul 2014 11:03:31 -0600
Date: 2014-07-08T11:03:31-06:00 [thread overview]
Message-ID: <CvVuv.204762$bA1.17573@fx22.iad> (raw)
In-Reply-To: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com>
On 07-Jul-14 08:23, NiGHTS wrote:
> A question about the variables in the Test.P type you introduced.
> I would like to make available to other spawned tasks these protected
> variables, so essentially Test.P needs to be a global of some kind
> with static data in the currently running process.
Not necessarily; you could use an access-discriminated task for these
spawned tasks.
Assuming:
package Test is
protected type P is
procedure Do_Something;
end P;
end Test;
We can do this:
with Test;
package Processes is
task type K(P : not null access Test.P) is
entry x( Input : in Integer );
entry y( Output : out Integer );
End K;
End Processes;
This will allow you to access the protected object you specify when you
declare the task; an example usage would be:
with
Test,
Processes;
procedure Main is
O : Aliased Test.P;
J : Processes.K(O'Access);
K : Integer;
begin
-- O.Do_Something;
J.Y(K); -- calls O.do_something internally.
end Main;
------------
-- Bodies --
------------
package body Test is
protected body P is
procedure Do_Something is
begin
Ada.Text_IO.Put_Line("Did Something!");
End Do_Something;
end P;
end Test;
package body Processes is
task body K is
Value : Integer:= 0;
begin
loop
select
accept x (Input : in Integer) do
Value:= Value + Input;
end x;
or
accept y (Output : out Integer) do
Output:= Value;
Value:= 0;
P.Do_Something;
end y;
or
terminate;
end select;
end loop;
End K;
End Processes;
next prev parent reply other threads:[~2014-07-08 17:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 7:15 Protected Type compiler complaint NiGHTS
2014-07-07 7:55 ` Simon Wright
2014-07-07 14:23 ` NiGHTS
2014-07-07 16:37 ` Adam Beneschan
2014-07-07 17:21 ` Simon Wright
2014-07-08 17:03 ` Shark8 [this message]
2014-07-08 17:50 ` Anh Vo
2014-07-07 19:06 ` framefritti
2014-07-08 7:11 ` Georg Bauhaus
2014-07-08 7:53 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox