
"Talbot, George" <Gtalbot@locuspharma.com> wrote in message news:acfee74296c36aa7458ec7c5580b0b9c4564c67b@locuspharma.com...
Hi,
I've attached to this e-mail a working prototype of a wrapper for shared_ptr that uses a spinlock so that the shared_ptr may be updated atomically from multiple threads. For example, two threads can both attempt to set the value of the same shared_ptr, and the last one will win. This wrapper includes a "compare_and_set" method for performing lock-free-style "read, copy, attempt swap, repeat" updating to a data structure, though, of course because the wrapper uses a spinlock, it isn't truly lock free.
I suggest you take a look at a mostly lock-free implementation: http://appcore.home.comcast.net/vzoom/refcount/ Your wrapper uses the spinlock when it doesn't have to... A swap and a cas to shared locations that contain pointers to the refcount object do not need to be locked... Weak reference count modifications do not need to be locked... You don't need to use DWCAS either...