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

Rainer Schuetze r.sagitario at gmx.de
Fri Feb 1 12:38:55 PST 2013



On 01.02.2013 21:02, Steven Schveighoffer wrote:
> 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.
>

It depends on the application. At work we put a lot of effort into 
transferring data lock-free from/to a low latency thread processing 
audio. No blocking is allowed in this thread. (You cannot guarantee this 
with D at the moment, but IMO it only takes a few tweaks to the runtime.)

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

Yes. My proposed code is only slightly more complex than atomic 
increments/decrements, but should also work for shared(Container).



More information about the Digitalmars-d mailing list