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,10d1a90a699d6cfc X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!q75g2000hsh.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: Ada tasking question Date: 18 Apr 2007 19:13:55 -0700 Organization: http://groups.google.com Message-ID: <1176948835.132931.32230@q75g2000hsh.googlegroups.com> References: <20070418201307.18a85fd9@cube.tz.axivion.com> NNTP-Posting-Host: 75.70.221.169 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1176948835 7732 127.0.0.1 (19 Apr 2007 02:13:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 19 Apr 2007 02:13:55 +0000 (UTC) In-Reply-To: <20070418201307.18a85fd9@cube.tz.axivion.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: q75g2000hsh.googlegroups.com; posting-host=75.70.221.169; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:15112 Date: 2007-04-18T19:13:55-07:00 List-Id: It is not efficient to create and destroy a number of tasks to do this job. It is more efficient to create a static set of tasks and let them cycle through the work as in the following example: with Ada.Text_Io; use Ada.Text_Io; procedure Task_Test_01 is subtype Return_Value is Natural range 0..100; subtype Index is Return_Value range 1..Return_Value'Last; protected Indexer is procedure Get_Index(Next_Index : out Return_Value); private Current_Index : Return_Value := Return_Value'Last; end Indexer; protected body Indexer is procedure Get_Index(Next_Index : out Return_Value) is begin Next_Index := Current_Index; if Next_Index > Return_Value'First then Current_Index := Current_Index - 1; end if; end Get_Index; end Indexer; type Buckets is array(Index) of Integer; The_Buckets : Buckets := (Others => 0); task type Worker is entry Set_Id(Id : Positive); end Worker; task body Worker is My_Index : Return_Value; Working_Value : Integer; Id_Num : Positive; begin accept Set_Id(Id : Positive) do Id_Num := Id; end Set_Id; loop Indexer.Get_Index(My_Index); exit when My_Index = Return_Value'First; Working_Value := 2 * My_Index; Put_Line("Worker" & Positive'Image(Id_Num) & " at work."); The_Buckets(My_Index) := Working_Value; end loop; end Worker; Team : array(1..5) of Worker; begin for I in Team'range loop Team(I).Set_Id(I); end loop; end Task_Test_01; Jim Rogers