Re: [boost] I think using spinlocks to simulate an atomicshared_ptr...

Thanks for looking at that. I was also thinking--does enable_shared_from_this need to have an "enable_atomic_from_this" version? That would also imply an atomic_weak type. -- George T. Talbot <gtalbot@locuspharma.com>
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Wednesday, November 15, 2006 11:42 AM To: boost@lists.boost.org Subject: Re: [boost] I think using spinlocks to simulate an atomicshared_ptr...
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).
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (1)
-
Talbot, George