Bug 15129 – std.parallelism.parallel doesn't enforce shared-correctness

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-09-30T08:40:40Z
Last change time
2024-12-01T16:25:09Z
Keywords
safe
Assigned to
No Owner
Creator
Marc Schütz
Depends on
1983, 11043
Blocks
18177
Moved to GitHub: phobos#10142 →

Comments

Comment #0 by schuetzm — 2015-09-30T08:40:40Z
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.
Comment #1 by nick — 2023-01-16T12:15:15Z
> it is sufficient for the context to be const, otherwise it probably needs to be immutable. `i` should be declared `shared` for safe mutation. To support that, the ParallelForeach.opApply delegate context parameter should require `shared` (which would allow `immutable` too). Unfortunately the opApply delegate doesn't support `shared` (or `immutable`) context inference AFAICT.
Comment #2 by nick — 2023-01-16T12:51:54Z
Both of these are examples of possible data races that should've been detected: https://issues.dlang.org/show_bug.cgi?id=23624 https://issues.dlang.org/show_bug.cgi?id=23634
Comment #3 by robert.schadek — 2024-12-01T16:25:09Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10142 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB