Parallel processing and further use of output

Zoidberg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 26 05:32:04 PDT 2015


> Here's a correct version:
>
> import std.parallelism, std.range, std.stdio, core.atomic;
> void main()
> {
>     shared ulong i = 0;
>     foreach (f; parallel(iota(1, 1000000+1)))
>     {
>         i.atomicOp!"+="(f);
>     }
>     i.writeln;
> }

Thanks! Works fine. So "shared" and "atomic" is a must?


More information about the Digitalmars-d-learn mailing list