Index: src/natools-parallelism.adb ================================================================== --- src/natools-parallelism.adb +++ src/natools-parallelism.adb @@ -63,6 +63,61 @@ pragma Unreferenced (Workers); begin null; end Single_Accumulator_Run; + + + procedure Per_Task_Accumulator_Run + (Global : in out Global_State; + Task_Count : in Positive) + is + protected State is + procedure Get_Next_Job + (Job : out Job_Description; + Terminated : out Boolean); + + procedure Gather (Result : in Task_Result); + end State; + + task type Worker is + end Worker; + + protected body State is + + procedure Get_Next_Job + (Job : out Job_Description; + Terminated : out Boolean) is + begin + Get_Next_Job (Global, Job, Terminated); + end Get_Next_Job; + + procedure Gather (Result : in Task_Result) is + begin + Gather_Result (Global, Result); + end Gather; + + end State; + + task body Worker is + Job : Job_Description; + Result : Task_Result; + Terminated : Boolean; + begin + Initialize (Result); + + loop + State.Get_Next_Job (Job, Terminated); + exit when Terminated; + Do_Job (Result, Job); + end loop; + + State.Gather (Result); + end Worker; + + Workers : array (1 .. Task_Count) of Worker; + pragma Unreferenced (Workers); + begin + null; + end Per_Task_Accumulator_Run; + end Natools.Parallelism; Index: src/natools-parallelism.ads ================================================================== --- src/natools-parallelism.ads +++ src/natools-parallelism.ads @@ -48,6 +48,42 @@ procedure Single_Accumulator_Run (Global : in out Global_State; Task_Count : in Positive); + + + generic + type Global_State (<>) is limited private; + -- State common to all jobs, only accessed from protected subprograms + + type Task_Result is limited private; + -- Accumulated result in a single task + + type Job_Description is limited private; + -- Parameters for a given job + + with procedure Initialize (Result : in out Task_Result) is <>; + -- Initialize Result for the current task + + with procedure Get_Next_Job + (Global : in out Global_State; + Job : out Job_Description; + Terminated : out Boolean) is <>; + -- If there is a next job available from Global, set Terminated + -- to False and initialize Job, otherwise set Terminated to True. + + with procedure Do_Job + (Result : in out Task_Result; + Job : in Job_Description) is <>; + -- Perform the job in parallel + + with procedure Gather_Result + (Global : in out Global_State; + Partial : in Task_Result) is <>; + -- Update Global with results stored in Partial + + procedure Per_Task_Accumulator_Run + (Global : in out Global_State; + Task_Count : in Positive); + end Natools.Parallelism;