[Issue 18468] New: cannot use `synchronized {}` in @safe code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 19 12:00:44 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=18468

          Issue ID: 18468
           Summary: cannot use `synchronized {}` in @safe code
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: iamthewilsonator at hotmail.com

@safe void main()
{
    synchronized {}
}

onlineapp.d(4): Error: safe function 'main' cannot access __gshared data
'__critsec15'
onlineapp.d(4): Error: safe function 'main' cannot access __gshared data
'__critsec15'
onlineapp.d(4): Error: variable onlineapp.main.__critsec15 __gshared not
allowed in safe functions; use shared

this is due to the compiler rewriting 
synchronized { foo();} // line 15
as
 __gshared ubyte[critsec.sizeof + size_t.sizeof] __critsec15;
_d_criticalenter(__critsec15.ptr);
try { foo(); } finally { _d_criticalexit(__critsec15.ptr); }

instead of 

 __gshared ubyte[critsec.sizeof + size_t.sizeof] __critsec15;
_d_criticalenter(&__critsec15[0]);
try { foo(); } finally { _d_criticalexit(&__critsec15[0]); }

--


More information about the Digitalmars-d-bugs mailing list