From: "Peter Walker" <p.walker@trinet.com>
Subject: question on tasks
Date: Sat, 18 Sep 2004 18:44:32 +1000
Date: 2004-09-18T18:44:32+10:00 [thread overview]
Message-ID: <414bf572@dnews.tpgi.com.au> (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;
-----------------------------
next reply other threads:[~2004-09-18 8:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-18 8:44 Peter Walker [this message]
2004-09-18 10:21 ` question on tasks Martin Dowie
2004-09-20 14:56 ` Peter Walker
2004-09-20 15:53 ` Martin Dowie
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox