comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: passing messages between the tasks
Date: Mon, 13 Oct 2014 18:49:08 -0700 (PDT)
Date: 2014-10-13T18:49:08-07:00	[thread overview]
Message-ID: <41154c4b-6158-4701-ab25-85afa3b24ed2@googlegroups.com> (raw)
In-Reply-To: <b7a2745e-a0df-400b-a057-828473919fee@googlegroups.com>

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

  reply	other threads:[~2014-10-14  1:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-14  1:17 passing messages between the tasks compguy45
2014-10-14  1:49 ` Adam Beneschan [this message]
2014-10-14  1:55   ` compguy45
2014-10-14  2:09   ` compguy45
2014-10-14  2:14     ` Adam Beneschan
2014-10-14  2:15       ` compguy45
2014-10-14  7:36         ` mockturtle
2014-10-14 15:30           ` compguy45
2014-10-14 16:25             ` mockturtle
2014-10-14 20:33             ` Shark8
2014-10-14 19:43   ` Shark8
2014-10-14 20:42     ` Jeffrey Carter
2014-10-14 21:08       ` compguy45
2014-10-14 21:58         ` compguy45
2014-10-14 23:03           ` Jeffrey Carter
2014-10-14 22:22         ` Shark8
2014-10-14 23:49         ` Dennis Lee Bieber
2014-10-15  1:07         ` Dennis Lee Bieber
replies disabled

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