Summary: Implicitly allowing objects which contain delegates to
                    be shared/immutable can cause races
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from Steven Schveighoffer <> 2011-09-30 
10:54:04 PDT ---
Consider this code:

class Foo
   this(ref int _i) { dg = (){return _i;} }
   ref int delegate() dg;

immutable Foo f;

int notShared;

shared static this()
   f = new Foo(notShared);

Since f is implicitly shared, it provides access to notShared from the main
thread's local storage without protections (locks or immutable guarantees). 
All one has to do is call the delegate dg.

I think in order to prevent this from accidentally happening, you should be
required to cast to either shared or immutable a delegate or anything that
contains a delegate (directly or indirectly).

The same issue occurs with shared.

This is related to bug 6741

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to