On 01.02.2013 21:02, Steven Schveighoffer wrote:
On Fri, 01 Feb 2013 14:03:51 -0500, Rainer Schuetze <[email protected]>
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).

Reply via email to