On Saturday, 28 May 2016 at 16:24:21 UTC, chmike wrote:
In my long quest to implement a flyweight pattern with objects
instantiated at compile time, I was indirectly notified of the
possible problem of synchronization.
In a flyweight pattern the user has the impression there are
distinct instances where in fact objects with the same state
(member variable value) are the same instance.
Since with play a trick with the users assumption, there is a
high risk that user produces logically invalid code when using
synchronization with such a flyweight object.
In order to avoid this problem I would need a solution to make
synchronization impossible on an object ? It is preferable if
this could be enforced at compile time. Is this possible with D
?
Not currently. However, there was a proposal to remove monitors
from objects by default unless they have a special UDA on them,
so if that change ever goes through it's as simple as not
annotating your class.
https://github.com/dlang/druntime/pull/789