* 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
* Re: question on tasks
2004-09-18 8:44 question on tasks Peter Walker
@ 2004-09-18 10:21 ` Martin Dowie
2004-09-20 14:56 ` Peter Walker
0 siblings, 1 reply; 4+ messages in thread
From: Martin Dowie @ 2004-09-18 10:21 UTC (permalink / raw)
"Peter Walker" <p.walker@trinet.com> wrote in message
news:414bf572@dnews.tpgi.com.au...
> Hi, is it possible to have a task do the following two things
> simultaneously:
No _exactly_ at the same time but I think I know what you mean...
...is this what you're after?
with Ada.Numerics.Float_Random; use Ada.Numerics;
with Ada.Text_Io; use Ada.Text_Io;
procedure Peter is
type Location is (Alpha, Beta);
package Communication_Buffer is
procedure C1 (A, B : Integer; C : String);
end Communication_Buffer;
package body Communication_Buffer is
procedure C1 (A, B : Integer; C : String) is
begin
Put_Line ("C1 got [" & C & "]");
end C1;
end Communication_Buffer;
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;
A, B : Integer := 0;
G : Float_Random.Generator;
begin
while not Done loop
select
accept Incoming (Source : Location; Destination : Location;
Message : String) do
Put_Line ("Recieved message " & Message & " from " &
Location'Image (Source));
end Incoming;
or
-- delay Duration (Random_Time.Random (Seed));
delay Duration (Float_Random.Random (G));
if Messages_To_Send > 0 then
Communication_Buffer.C1 (A, B, "Hello");
Messages_To_Send := Messages_To_Send - 1;
end if;
end select;
end loop;
end A;
begin
A.Incoming (Alpha, Beta, "foo");
end Peter;
^ 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