Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-15 11:41:32


Sorry for the brief response, no time...

Talbot, George wrote:

> 2) Without any sort of 2-pointer-wide atomic assignment in hardware,
> operator= really looks like this:
>
> lock the source pointer
> make a local copy of it
> release the source pointer
>
> lock the destination
> set the value of the destination from the copy
> unlock the destination
>
> This won't deadlock, but has to make an extra copy of the pointer
> locally.

There's no extra copy. shared_ptr::operator= does:

shared_ptr( r ).swap( *this );

and the above does:

lock source
shared_ptr tmp( src );
unlock

lock dest
dest.swap( tmp );
unlock

so the two are equivalent (modulo spinlock order).


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