From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-10-22 06:21:28


Chris Thomasson wrote:

> One thing I forgot to mention in my last post, nit-picking, your
> algorithm sketch invoked the user-provided destructor in the context
> of the critical-section provided by the lock that is associated with
> the count ptr. Can't call function pointers while you hold a lock? ;)

Yes, I "oversimplified" a bit. *this = rhs is a shorthand for shared_ptr(
rhs ).swap( *this ) and the copy/destroy parts of it need to be outside the
lock:

void replace( shared_ptr rhs )

    take write (rw)spinlock for this
    this->swap( rhs )
    release spinlock

Another mistake was that the spinlock should be associated with 'this', not
with the pointer to count as in your scheme.