[Issue 6747] New: Implicitly allowing objects which contain delegates to be shared/immutable can cause races

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 30 10:54:43 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6747

           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
        AssignedTo: nobody at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list