[Issue 15129] New: std.parallelism.parallel doesn't enforce shared-correctness

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Sep 30 01:40:40 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=15129

          Issue ID: 15129
           Summary: std.parallelism.parallel doesn't enforce
                    shared-correctness
           Product: D
           Version: D2
          Hardware: x86_64
               URL: http://forum.dlang.org/post/fprccfrqntxqbsrbrtfh@forum
                    .dlang.org
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: schuetzm at gmx.net
        Depends on: 1983, 11043

This compiles:

    ulong i = 0;
    foreach (f; parallel(iota(1, 1000000+1)))
    {
        i += f;
    }
    thread_joinAll();
    i.writeln;

The delegate to which the function body is converted has mutable references to
thread-local data, and should therefore be rejected.

If parallel takes its delegate via scope (as it should), and there are no
aliases to the context passed to parallel() (e.g. as a second parameter), it is
sufficient for the context to be const, otherwise it probably needs to be
immutable.

--


More information about the Digitalmars-d-bugs mailing list