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: nob...@puremagic.com Reporter: iamthewilsona...@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]); } --