comp.lang.ada
 help / color / mirror / Atom feed
* question on tasks
@ 2004-09-18  8:44 Peter Walker
  2004-09-18 10:21 ` Martin Dowie
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Walker @ 2004-09-18  8:44 UTC (permalink / raw)


Hi, is it possible to have a task do the following two things 
simultaneously:

1) sent a finite number of message to another task as random times
2) listen in on incoming messages and acknowledge them.

for example, the taskA would send 3 messages at random times to some 
communication_buffer (which relays messages to other tasks). taskA would 
also listen for incoming messages and print them to standard output.

I have tried to use the following to perform the above, but it does not 
work. Would anyone know how to implement the above?

Many thanks.
Peter

----------------------------
   task A is
      entry Incoming (Source : Location; Destination : Location; Message : 
String);
   end A;


   task body A is
      Done : Boolean := False;
      Messages_To_Send : Integer := 3;
      ...
   begin

      while not Done loop

         select

            accept Incoming (Source : Location; Destination : Location) do
               Put_Line("Recieved message " & Message & " from " & 
Location'Image(Source));
            end C1;

         else

            if Messages_To_Send > 0 then
               delay Duration(Random_Time.Random(Seed)); -- some random 
number between 1 and 10
               Communication_Buffer.C1(A, B, "Hello");
               Messages_To_Send := Messages_To_Send - 1;
               ...
            end if;

         end select;

      end loop;

   end A;
-----------------------------







^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-09-20 15:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-18  8:44 question on tasks Peter Walker
2004-09-18 10:21 ` Martin Dowie
2004-09-20 14:56   ` Peter Walker
2004-09-20 15:53     ` Martin Dowie

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