[dmd-concurrency] draft 7

Andrei Alexandrescu andrei at erdani.com
Mon Feb 1 14:16:03 PST 2010


Michel Fortin wrote:
> Le 2010-02-01 à 16:49, Andrei Alexandrescu a écrit :
> 
>> I think swap could be typed as:
>>
>> swap(scope ref int[], scope ref int[]);
>>
>> The point of scope parameter typechecking is that swap does not save a reference surreptitiously; I think escaping to another scope parameter should be fine (if somewhat conservative).
> 
> It's not safe unless the compiler enforcse that all scoped parameters belong to the same owner object. Otherwise you could exchange them between too different objects and unless there is no aliasing they'd now each be owned by two locks!

Could you please give an example?

>> In fact I've had this idea for a while now that "ref" should imply "I won't escape it". That would make ref strictly pass-down. Walter is mildly favorable to that idea. I think it's worth giving it a closer look now.
> 
> This has some far-reaching consequences: since the 'this' of a struct is a 'ref', you wouldn't be able to take the address of a member.

You can take the address, you can't escape it, which is fine. Also, you 
can pass down a ref to the field, which is kind of the purpose of the 
limitation.


Andrei


More information about the dmd-concurrency mailing list