[dmd-concurrency] draft 8: the final countdown

Michel Fortin michel.fortin at michelf.com
Thu Feb 11 04:08:43 PST 2010


Le 2010-02-10 à 18:02, Andrei Alexandrescu a écrit :

> I see; good idea. So everything not marked explicitly as shared, at any level, would be considered owned and can't escape. Beyond a point, the switch is turned and stuff becomes shared, and so can escape no problem.

Exactly.


> I'll talk to Walter about what it takes to implement this.
> 
> This scheme only works for arrays and pointers, but they are frequent enough to warrant such a rule. Classes remain the way they are - they have to fend for themselves.


If I'm not mistaken access to struct and class fields behind an indirection should be safe too if you access them directly from the synchronized method. As long as you don't need to pass the reference to a function it should be safe and not require a cast.


> Thanks! This is a great idea.


You're welcome. I'm glad you like it. :-)

Note that you have to be careful about assignments too. Say you have "int* x": since the integer is owned the compiler should not allow assignment "x = something;" because you could end up assigning something that someone else has a reference to; a pre-leaked reference if you want. So assignment to "x" would require a cast. There could be an exception for "x = new int;", but for struct and classes it works only when you're not using a constructor that leaks a reference.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list