How to call stop from parallel foreach

jfondren julian.fondren at gmail.com
Fri Jun 25 20:15:12 UTC 2021


On Friday, 25 June 2021 at 19:52:23 UTC, seany wrote:
> On Friday, 25 June 2021 at 19:30:16 UTC, jfondren wrote:
>> On Friday, 25 June 2021 at 19:17:38 UTC, seany wrote:
>>> If i use `parallel(...)`it runs.
>>>
>>> If i use `prTaskPool.parallel(...`, then in the line : `auto 
>>> prTaskPool = new TaskPool(threadCount);` it hits the error. 
>>> Please help.
>>
>> parallel() reuses a single taskPool that's only established 
>> once.
>>
>> Your code creates two TaskPools per a function invocation and 
>> you
>> call that function in a loop.
>>
>> stracing your program might again reveal the error you're 
>> hitting.
>
> I have removed one - same problem.
> Yes, I do call it in a loop. how can I create a taskpool in a 
> function that itself will be called in a loop?

One option is to do as parallel does:
https://github.com/dlang/phobos/blob/master/std/parallelism.d#L3508


More information about the Digitalmars-d-learn mailing list