Very limited shared promotion

Timon Gehr timon.gehr at gmx.ch
Wed Jun 19 13:56:01 UTC 2019


On 19.06.19 05:11, Manu 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.

Ok. I guess it suffices to say that it does not. (If you can promote the 
entire stack frame to `shared` temporarily, you can just as easily 
promote only the part of the stack frame that your delegate actually 
wants to capture.)

> 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,

I don't know yet what the _most general_ implicit `shared` promotion 
rules could be, but I think I know how to do it in the type system for 
your specific case.

For memory ordering, we can just say that because there is `scope` on 
the delegate, any @trusted code that sends it to other threads 
temporarily is clearly already required to set up the respective memory 
barriers. (Because it needs to ensure that the deletion of all 
references to the closure context in all other threads is ordered before 
the owning thread returns.)

> then we are done here and I will buy you a years supply of beer.
> ...

I don't drink. :)

> Coupled with removing read/write access from shared, that is
> everything I need to go away and leave you all alone.
> 

Then we are on the same page, but this will need a DIP, so it would make 
sense to think about it a bit more and to convince Walter that it can work.


More information about the Digitalmars-d mailing list