And so you can have both thread-safe synchronized heavy-duty container and a fast and small container all in one just by overloading the appropriate methods and adding appropriate synchronization blocks in the shared ones. This is one of those "little" advantages of D over C++, that make my life _SO_ much easier.
On Tue, Oct 25, 2011 at 4:44 PM, Timon Gehr <[email protected]> wrote: > 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. >
