
15 Nov
2006
15 Nov
'06
4:41 p.m.
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).