Is it possible to forbid synchronization on an object ?
    Meta via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat May 28 09:31:02 PDT 2016
    
    
  
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
    
    
More information about the Digitalmars-d-learn
mailing list