Very limited shared promotion
Manu
turkeyman at gmail.com
Wed Jun 19 03:20:41 UTC 2019
On Wed, Jun 19, 2019 at 1:11 PM Manu <turkeyman at gmail.com> wrote:
>
> On Wed, Jun 19, 2019 at 12:20 AM Timon Gehr via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
> >
> > On 18.06.19 16:14, Timon Gehr wrote:
> > > On 18.06.19 16:13, Timon Gehr wrote:
> > >>
> > >> int sum(){ // note: just to illustrate the concept
> > >> int result=0;
> > >> foreach(i;iota(1000).parallel){
> > >> static assert(is(typeof(result)==shared(int)));
> > >> result.atomic!"+="(i);
> > >> }
> > >> static assert(is(typeof(result)==int));
> > >> return result;
> > >> }
> > >
> > > Return type should have been int, of course...
> >
> > And there should have been is expressions. Getting tired from pushing
> > back against all the nonsense. Just note that if you can make the above
> > work with useless qualified capturing, you can do so with useful
> > qualified capturing and this is so blatantly obvious that it causes me
> > physical pain that Manu honestly does not see it.
>
> I can't see it because the design specifically inhibits that static
> assert in the loop body.
> But I will revoke my opinion on this matter; arguing will only slow it
> down. If you know how to make that *EXACT* code you wrote above work,
> then we are done here and I will buy you a years supply of beer.
>
> Coupled with removing read/write access from shared, that is
> everything I need to go away and leave you all alone.
I'll just tweak your example one more little bit to make sure
absolutely everything I care about is captured correctly:
struct S {
int result;
void inc(int i) shared { result.atomic!"+="(i); }
}
int sum(){
S s;
foreach(i; iota(1000).parallel){
static assert(is(typeof(s) == shared(S)));
s.inc(i);
}
static assert(is(typeof(s) == S));
return s.result;
}
The combinations of primitives at work here will solve every challenge
I'm aware of in our engine.
More information about the Digitalmars-d
mailing list