Parallel processing and further use of output
Zoidberg via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 26 05:18:15 PDT 2015
I've run into an issue, which I guess could be resolved easily,
if I knew how...
[CODE]
ulong i = 0;
foreach (f; parallel(iota(1, 1000000+1)))
{
i += f;
}
thread_joinAll();
i.writeln;
[/CODE]
It's basically an example which adds all the numbers from 1 to
1000000 and should therefore give 500000500000. Running the above
code gives 205579930677, leaving out "thread_joinAll()" the
output is 210161213519.
I suspect there's some sort of data race. Any hint how to get
this straight?
More information about the Digitalmars-d-learn
mailing list