From: "Martin Dowie" <martin.dowie@btopenworld.com>
Subject: Re: question on tasks
Date: Sat, 18 Sep 2004 10:21:44 +0000 (UTC)
Date: 2004-09-18T10:21:44+00:00 [thread overview]
Message-ID: <cih27o$md0$1@sparta.btinternet.com> (raw)
In-Reply-To: 414bf572@dnews.tpgi.com.au
"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;
next prev parent reply other threads:[~2004-09-18 10:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-18 8:44 question on tasks Peter Walker
2004-09-18 10:21 ` Martin Dowie [this message]
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