Synchronized Classes and Struct Members

Timon Gehr timon.gehr at gmx.ch
Tue Oct 25 05:44:26 PDT 2011


On 10/25/2011 02:33 PM, Gor Gyolchanyan wrote:
> Yes. The shared-ness, const-ness or immutable-ness of the _this_
> parameter is defined by marking the method itself shared, const or
> immutable respectively.
> But marking the method shared or immutable makes that method callable
> _ONLY_ for shared or immutable objects of that class or struct
> respectively.
> In order to make that struct usable from both shared and non-shared
> contexts, you need to have 2 overloads of that method: shared and
> non-shared.
>

Yes, indeed: One that is efficient and correct in an unshared context 
and one that _actually works_ if sharing is going on. The two D 
implementations are the same only in toy examples, and since memory 
barriers have to be inserted for the shared one, the two methods 
necessarily compile to different machine code.


More information about the Digitalmars-d mailing list