pass-by-ref semantics for structs (was Deque impl.)

Steven Schveighoffer schveiguy at yahoo.com
Fri Feb 1 12:02:15 PST 2013


On Fri, 01 Feb 2013 14:03:51 -0500, Rainer Schuetze <r.sagitario at gmx.de>  
wrote:
>
> The problem is to make it atomic without expensive locks. Lacking the  
> CAS2 operation (that does a CAS on two arbitrary memory locations  
> simultaneously), my first thought was that it is not possible.

I don't think expensive locks are an issue here.  Having an expensive lock  
to copy a pointer from a shared location into a thread-local location is  
worth having an expensive lock, and may even be necessary.

Once you have the thread-local copy of the reference, incrementing and  
decrementing the reference count can be done via CAS.

-Steve


More information about the Digitalmars-d mailing list