From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me
X-Spam-Level:
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,XPRIO autolearn=ham
autolearn_force=no version=3.4.4
X-Google-Thread: 103376,c3c8df11bdf1d9da,start
X-Google-Attributes: gid103376,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Peter Walker"
Newsgroups: comp.lang.ada
Subject: question on tasks
Date: Sat, 18 Sep 2004 18:44:32 +1000
Organization: -
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 220.244.246.157
X-Original-NNTP-Posting-Host: 220.244.246.157
Message-ID: <414bf572@dnews.tpgi.com.au>
X-Trace: dnews.tpgi.com.au!tpg.com.au 1095497074 220.244.246.157 (18 Sep 2004
18:44:34 +1000)
Path:
g2news1.google.com!news2.google.com!proxad.net!newsfeed.stueberl.de!solnet.ch!solnet.ch!nntp.gblx.net!nntp3.phx1!dnews.tpgi.com.au!tpg.com.au!not-for-mail
Xref: g2news1.google.com comp.lang.ada:3822
Date: 2004-09-18T18:44:32+10:00
List-Id:
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;
-----------------------------