https://issues.dlang.org/show_bug.cgi?id=23709
RazvanN <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |INVALID --- Comment #7 from RazvanN <[email protected]> --- This is not a bug. The compiler rewrites the code to: auto tmp = c; _d_monitorenter(tmp); try { body } finally { _d_monitorexit(tmp); } So the reading of c needs to be atomic. Note that the original example (synchronized(new shared Class)) currently compiles because creating a shared instance does not need to be protected by a mutex. So just write: import core.atomic; class Class {} void main() { shared Class c; synchronized(atomicLoad(c)) {} } And the code will compile. Arguably, the compiler could automatically wrap `c` into an `atomicLoad`, however, that's based on the assumption that druntime is available and that the users does not employ a different synchronization mechanism. I will tentatively close this as INVALID, but please reopen if I am missing something. --
