[dmd-concurrency] is shared going to be a type modifier?

Sean Kelly sean at invisibleduck.org
Thu Jan 7 09:21:56 PST 2010


On Jan 7, 2010, at 8:36 AM, Steve Schveighoffer wrote:

> I'm not quite understanding everything being discussed here, because I came into this discussion quite late, but is shared going to remain a type modifier?
> 
> People are mentioning shared as a storage class on member variables, but I thought shared was going to be like const, where it transitively affects all members.  I thought a shared member function is one which the 'this' pointer is marked as shared, similar to a const function.  If that's the case, aren't all unmarked variables in a class shared?  Why the need to mark them?  And how do you have a 'partially shared' class where some members are marked shared and some are not?

I think the idea was exactly as you're describing.  But consider this:

class A
{
    void fnA() synchronized { x = 5; }
    void fnB() shared { x = 6; }
    int x;
}

In this case, the field x is used in both a synchronized and shared function.  Since any use of x is outside a synchronized function, all accesses to it must be made atomic, and the compiler has to be able to determine this and enforce it.  Also, I'm simply not sure that use of shared fields will be so common that we want it to be automatic like this.


More information about the dmd-concurrency mailing list