[Issue 19984] Support shared in foreach lambdas
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 10 19:55:16 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=19984
--- Comment #5 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Your example implicitly converts thread local data to shared:
---
struct S {
int result;
int[] data;
void inc(int i) shared { result.atomic!"+="(i); }
}
shared int[] data;
int sum(){
S s;
s.data=[0,1,2];
foreach(i; iota(1000).parallel){
static assert(is(typeof(s) == shared(S)));
s.inc(i);
data=s.data;
}
static assert(is(typeof(s) == S));
assert(s.data[0]==0,"now it's local and shared");
return s.result;
}
---
--
More information about the Digitalmars-d-bugs
mailing list