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.236.228.202 with SMTP id f70mr1671119yhq.28.1413251350016; Mon, 13 Oct 2014 18:49:10 -0700 (PDT) X-Received: by 10.50.134.164 with SMTP id pl4mr7512igb.0.1413251349919; Mon, 13 Oct 2014 18:49:09 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!dc16no2678174qab.1!news-out.google.com!rp1ni29760igb.0!nntp.google.com!h18no5581935igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 13 Oct 2014 18:49:08 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=66.126.103.122; posting-account=KSa2aQoAAACOxnC0usBJYX8NE3x3a1Xq NNTP-Posting-Host: 66.126.103.122 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <41154c4b-6158-4701-ab25-85afa3b24ed2@googlegroups.com> Subject: Re: passing messages between the tasks From: Adam Beneschan Injection-Date: Tue, 14 Oct 2014 01:49:09 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3248 X-Received-Body-CRC: 3858190572 Xref: news.eternal-september.org comp.lang.ada:22440 Date: 2014-10-13T18:49:08-07:00 List-Id: On Monday, October 13, 2014 6:17:29 PM UTC-7, comp...@gmail.com wrote: > I understand in this example that calling tasks(main or environmental task) is passing id value to 2 tasks...In regarding to code below I have 2 question and was hoping someone can answer.... > > 1 with Ada.Text_IO, Ada.Integer_Text_IO; > 2 use Ada.Text_IO, Ada.Integer_Text_IO; > 3 > 4 procedure SomeProcedure is > 5 > 6 task type lamp is > 7 entry reset(id : Integer); > 8 end lamp; > 9 > 10 lamps : array (1..6) of lamp; > 11 > 12 task body lamp is > 13 begin > 14 Put_Line("Body of task lamp"); > 15 accept reset(id : Integer) do > 16 put("inside reset"); > 17 put(id); > 18 New_Line; > 19 end reset; > 20 delay 4.0; > 21 put("after accept"); > 22 end lamp; > 23 > 24 begin > 25 lamps(1).reset(id => 1); > 26 lamps(2).reset(id => 2); > 27 end SomeProcedure; > > 1. How would would these 2 tasks send message back to main? For example how would each of these two lamp tasks send "i received call to my acceptstatement"); An entry can have OUT (or IN OUT) parameters. If you want the "accept" to send something back to the task that calls the entry, define the entry with an OUT parameter, and set this parameter inside the ACCEPT statement. For a String, the problems with using a String as an OUT parameter are the same as for procedures--you can't really return a variable-length string this way. However, you can use Ada.Strings.Unbounded.Unbounded_String: entry reset(id : Integer; message : out Unbounded_String); and then in the accept statement: message := To_Unbounded_String("I received my call"); and then in the main: lamps(1).reset(id=>1, message=>The_Message); where The_Message is a variable or whatever. > 2. If there are some variables inside the body of the task to be saved and they might be different for each of these tasks how to save these values? You'll have to be clearer on what you mean by this. -- Adam