comp.lang.ada
 help / color / mirror / Atom feed
From: mockturtle <framefritti@gmail.com>
Subject: Re: passing messages between the tasks
Date: Tue, 14 Oct 2014 09:25:14 -0700 (PDT)
Date: 2014-10-14T09:25:14-07:00	[thread overview]
Message-ID: <3cca54b6-7144-4f97-ac2f-1de7cc119e28@googlegroups.com> (raw)
In-Reply-To: <52c27795-4b83-4409-af5f-fb24299845f3@googlegroups.com>

On Tuesday, October 14, 2014 5:30:58 PM UTC+2, comp...@gmail.com wrote:
> how would you be able to recal these values...
> 
> say i want to print b of task 1
> and I of task 2

The first solution that comes to my mind (and maybe the only one) is to provide your task with two entries: one to read the value of B and the other to read the value of I.  Those entries would have a OUT parameter where the task will write the desired values.  The accept statement would look something like 

   accept Get_I(Result: out Integer) do
     Result := I;
   end Get_I;

and you could use something like

    Lamps(2).Get_I(V);
    put_line(Integer'Image(V));

Of course, the accept statement causes a "synchronization" between the "main task" and task Lamps(2), so that when the execution reaches "Lamps(2).Get_I(V)" the main task will stop until Lamps(2) reaches the "accept" statement.

If this synchronized behavior is undesired (you want to query I and B at any time, "asynchronously") I guess that the only solution is using a protected object.  In this case things get a bit more complicated, but a possible solution could be this  (disclaimer: I did not check the code)

  1.  You declare a protected type (call it "Protected_Buffer") with procedures like "Set_I", "Get_I", ...  In this case Get_I and Get_B can be functions

  2.  When the lamp task starts it allocates a Protected_Buffer with new 

  3.  The lamp task updates the values of B and I by using the methods Set_I and Set_B of the protected object

  4.  In order to allow the "main task" to access the values stored in the protected object, the lamp task needs to "export" the access to the allocated buffer.  This can be done by providing the task with an entry similar to

      type Buffer_Access is access to Protected_Buffer;
      entry Get_Buffer_Access(acc : out Buffer_Access);

  5.  The main task first gets the access to the protected buffer by calling something like

    Lamps(2).Get_Buffer_Access(acc);

then it can print the value of, say, I by calling

    Put_Line(Integer'Image(acc.Get_I));

A problem with this solution is that the main task could write the values of I and B by calling, say, acc.Set_I(42).  If this is a problem, I think you can "wrap" the protected object inside a tagged type, make "Get" functions "public" while "Set" procedures "private."  


Lots of details left to the reader...  :-)

Riccardo


  reply	other threads:[~2014-10-14 16:25 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
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 [this message]
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