Sharing in D

Sean Kelly sean at invisibleduck.org
Thu Jul 31 22:53:04 PDT 2008


== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Sean Kelly wrote:
> > Sounds like the addition of a thread-local storage class (which
> > I've been asking for since I discovered D),
> It's actually implemented in D 2.0 as the __thread storage class,
> however it's for testing purposes only.

Yeah, I saw that.  If only it were in D 1.0 :-)

> > plus some language
> > checking on top of that.  I'll admit to being somewhat concerned
> > that the checking aspect will incur an unwanted runtime expense,
> > as I don't believe there's any way at compile-time to detect that
> > a variable is being accessed by multiple threads.
> It's done statically by the type - a shared type can be accessed by
> multiple types, an unshared type cannot.

What about this:

    shared ClassA a;

    void main()
    {
        ClassB b = a.getB();
        b.mutate();
    }

I'd imagine the checking will catch common mistakes but not issues
like the above?  Or will the fact that 'b' is being returned from
a require the declaration of 'b' to be shared because the value
may be accessed by both ClassA and anything outside ClassA?


Sean



More information about the Digitalmars-d mailing list