Error running concurrent process and storing results in array

drug drug2004 at bk.ru
Wed May 6 18:29:12 UTC 2020


06.05.2020 16:57, Steven Schveighoffer пишет:
>> ```
>> foreach(i; 0..n) // instead of for(long i = 0; i < n;)
>> ```
>> I guess that `proc` delegate cant capture `i` var of `foreach` loop so 
>> the range violation doesn't happen.
> 
> foreach over a range of integers is lowered to an equivalent for loop, 
> so that was not the problem.

I was surprised but `foreach` version do not have range violation, so 
there is difference between `foreach` and `for` loops. I did not try 
DerivedThread at all, only suggested them to avoid var capture. I just 
changed `for` by `foreach` and range violation gone. Probably this is 
implementation details.



More information about the Digitalmars-d-learn mailing list