Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-09 18:40:18


Talbot, George wrote:
> Hi,
>
> I have a question for the designers and implementers of
> boost::shared_ptr:
>
> Is there any plan afoot to support lock-free programming using
> shared_ptr? I was fooling around with wanting to attempt lock-free
> update of a tree structure that I have that uses shared_ptr. If
> no-one's thinking about this, how might I go about implementing:
>
> bool boost::shared_ptr<T>::compare_and_swap(T* original,
> shared_ptr<T>& new_one)

Very, very difficult. :-) shared_ptr is not atomic; you can look at Joe
Seigh's atomic_ptr:

http://atomic-ptr-plus.sourceforge.net/

and Chris Thomasson's

http://appcore.home.comcast.net/vzoom/refcount/

for examples of atomic reference counted pointers.

Shared_ptr can be made atomic by using a spinlock. This isn't really
lock-free, though.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk