Boost logo

Boost :

From: Chris Thomasson (cristom_at_[hidden])
Date: 2006-11-22 23:31:46

"Talbot, George" <Gtalbot_at_[hidden]> wrote in message
> 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:

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...

Boost list run by bdawes at, gregod at, cpdaniel at, john at