[Issue 14251] synchronized (mtx) doesn't check attributes (pure, const)

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Aug 30 07:01:44 PDT 2016


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

--- Comment #15 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Lodovico Giaretta from comment #14)
> (In reply to Andrei Alexandrescu from comment #13)
> > Can someone produce an example in which invariants promised by D's system
> > are broken?
> 
> immutable provides a strong guarantee, that allows me to put my immutable
> data in ROM. If I manage to have an immutable object allocated in ROM and
> someone tries to synchronize on it, my program will (in the best case) crash
> with a segmentation fault, as the synchronized statement tries to modify a
> mutex that is located in ROM.

That's not the case. The compiler knows the object has mutable metadata and
won't allow placing it in read-only pages.

--


More information about the Digitalmars-d-bugs mailing list