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 X-Received: by 10.112.140.170 with SMTP id rh10mr3745567lbb.7.1404839011551; Tue, 08 Jul 2014 10:03:31 -0700 (PDT) Path: border2.nntp.dca.giganews.com!nntp.giganews.com!w7no9743661lbi.1!news-out.google.com!v4ni35257lbb.0!nntp.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.112.MISMATCH!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx22.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:32.0) Gecko/20100101 Thunderbird/32.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Protected Type compiler complaint References: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com> In-Reply-To: <35cd9c91-4b2c-4baa-9ef6-3c69fd7086ce@googlegroups.com> Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Tue, 08 Jul 2014 17:03:30 UTC Organization: TeraNews.com Date: Tue, 08 Jul 2014 11:03:31 -0600 X-Received-Bytes: 2930 X-Received-Body-CRC: 2642167184 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Original-Bytes: 2945 Xref: number.nntp.dca.giganews.com comp.lang.ada:187457 Date: 2014-07-08T11:03:31-06:00 List-Id: 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;