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

Reply via email to