www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15129] New: std.parallelism.parallel doesn't enforce

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 puremagic.com
          Reporter: schuetzm 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.

--
Sep 30 2015