Template error and parallel foreach bug?

Ben Grabham Evil.Nebster at gmail.com
Sat Jun 4 19:55:29 PDT 2011


On 04/06/11 20:16, simendsjo wrote:
> On 04.06.2011 20:04, Timon Gehr wrote:
>> ulong SumMultiple3Or5_parallel(uint below) {
>> ulong sum;
>> foreach(i; parallel(iota(below))) {
>> if(i % 3 == 0 || i % 5 == 0)
>> sum += i; // low level data race here.
>> }
>> return sum;
>> }
>>
>> Loop iterations in a parallel foreach loop must be independent of each
>> other.
>>
>
> I thought paralellism was using locks behind the scenes. Guess I'll have
> to read the documentation then :)

You can always try reduce and map :) I can't remember whether they are 
parallel or not though!


More information about the Digitalmars-d-learn mailing list