Parallel processing and further use of output
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 26 09:10:31 PDT 2015
On Saturday, 26 September 2015 at 13:09:54 UTC, Meta wrote:
> On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote:
>> foreach (f; parallel(iota(1, 1000000+1)))
>> {
>> synchronized i += f;
>> }
>
> Is this valid syntax? I've never seen synchronized used like
> this before.
I'm sure it's valid.
A mutex is created for that instance of synchronized. I.e., only
one thread can execute that piece of code at a time.
If you're missing the braces, they're optional for single
statements, as usual.
http://dlang.org/statement.html#SynchronizedStatement
More information about the Digitalmars-d-learn
mailing list