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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c3c8df11bdf1d9da X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.uni-stuttgart.de!carbon.eu.sun.com!btnet-feed5!btnet!news.btopenworld.com!not-for-mail From: "Martin Dowie" Newsgroups: comp.lang.ada Subject: Re: question on tasks Date: Sat, 18 Sep 2004 10:21:44 +0000 (UTC) Organization: BT Openworld Message-ID: References: <414bf572@dnews.tpgi.com.au> NNTP-Posting-Host: host81-152-56-142.range81-152.btcentralplus.com X-Trace: sparta.btinternet.com 1095502904 22944 81.152.56.142 (18 Sep 2004 10:21:44 GMT) X-Complaints-To: news-complaints@lists.btinternet.com NNTP-Posting-Date: Sat, 18 Sep 2004 10:21:44 +0000 (UTC) X-RFC2646: Format=Flowed; Response X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MSMail-Priority: Normal X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Xref: g2news1.google.com comp.lang.ada:3823 Date: 2004-09-18T10:21:44+00:00 List-Id: "Peter Walker" 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;