From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: 'Number_Of_CPUs' tasks creation, with discriminants, running simultaneously. Date: Mon, 20 Jul 2020 19:45:54 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 20 Jul 2020 17:45:54 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="a4cf3d5e9f1e1c806eb81533e584ef28"; logging-data="24627"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NaRNOQEW8REUWjnpfkUFZYiR/f9Lav0c=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Cancel-Lock: sha1:dwsGszxZDMxnJO8iZSrTn+iqJuo= In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:59484 List-Id: On 7/20/20 3:51 PM, Olivier Henley wrote: > > My goal is to distribute similar work across multiple tasks. Incidentally, I want those tasks to start simultaneously, each task having some 'indexed' work (discriminants), and ideally block from main until they are done with their workload. > > I tried with an array of tasks, but the problem becomes I do not know either how to start them simultaneously with parametrization or coordinate their exit point with main. For simple parameterization, you can use a discriminant with a default that is a function call: subtype Task_ID is Integer range 0 .. System.Multiprocessors.Number_Of_CPUs; subtype Valid_Task_ID is Task_ID range 1 .. Task_ID'Last; Last : Task_ID := 0; function Next_ID return Valid_Task_ID is begin Last := Last + 1; return Last; end Next_ID; task type T (ID : Valid_Task_ID := Next); type T_Set is array (Valid_Task_ID) of T; Worker : T_Set; Each Worker (i) will have its ID determined during elaboration, and they will all start at the "begin" that follows the declaration of Worker. The order of the discriminants is arbitrary; there is no guarantee that Worker (I) will have ID of I. Elaboration is sequential, so each Worker will have a unique ID. [I think Ada 2X will allow a way to insure that the ID equals the index, but I'm not sure how it will work.] To block a subprogram until the Worker tasks all complete, declare them in a block statement: Create_Workers : declare Worker : T_Set; begin null; end Create_Workers; -- Jeff Carter "You've got the brain of a four-year-old boy, and I bet he was glad to get rid of it." Horse Feathers 47