comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: 'Number_Of_CPUs' tasks creation, with discriminants, running simultaneously.
Date: Mon, 20 Jul 2020 19:45:54 +0200	[thread overview]
Message-ID: <rf4l8i$o1j$1@dont-email.me> (raw)
In-Reply-To: <f3eac0d8-478d-492f-ab0b-17bd37e21095o@googlegroups.com>

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

  parent reply	other threads:[~2020-07-20 17:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-20 13:51 'Number_Of_CPUs' tasks creation, with discriminants, running simultaneously Olivier Henley
2020-07-20 13:55 ` Olivier Henley
2020-07-20 17:45 ` Jeffrey R. Carter [this message]
2020-07-20 20:31   ` Olivier Henley
2020-07-22 19:05     ` onox
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox