[Issue 10794] New: Unsynchronized access to data of syncronized class

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 11 10:11:31 PDT 2013


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

           Summary: Unsynchronized access to data of syncronized class
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: freeslave93 at gmail.com


--- Comment #0 from Roman <freeslave93 at gmail.com> 2013-08-11 10:11:30 PDT ---
Here is something similar to example from Alexandrescu's book (13.14.1
Temporary Protection == No Escape):

import std.stdio;

int* ptr;

void sneaky(out int bar)
{
    ptr = &bar;
}

synchronized class B
{
    private int bar;
    public void foo()
    {
        sneaky(bar);
    }
    int getBar()
    {
        return bar;
    }
    void setBar(int b)
    {
        bar = b;
    }
}

void main()
{
    auto b = new shared(B);
    b.setBar(5);
    b.foo();
    *ptr = 6;
    writeln(*ptr);
    writeln(b.getBar());
}

I just replaced 'ref' with 'out' and now it compiles fine. Is it suppose to
work this way?

I also wonder why we have to write 'new shared(NameOfClass)' when class is
synchronized, although we can't create not shared instance of synchronized
class. Was it designed to make code more explicit?

-- 
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