Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Peter Dimov Date : Fri Apr 15 2005 01:42 am Joe Seigh wrote: > On Thu, 14 Apr 2005 16:53:13 +0300, Peter Dimov > wrote: >> Joe Seigh wrote: >>> The atomic swap is one part. The other part is safely incrementing >>> the reference count without "owning" it first. There's the DWCAS >>> solution, the PPC solution, and various GC based solutions using >>> RCU, SMR, etc... And of course the 2CAS solution which only works on >>> MC68020 and MC68030 processors. >> >> You mean the race between >> >> atomic_ptr p2( p1 ); >> >> and >> >> p1 = 0; >> >> ? > > Yes. I must be missing something because I think this can be fixed easily: atomic_ptr<>::assign( atomic_ptr & other ) // other is unshared atomic_ptr temp( *this ); atomically set *this to other set other to empty // destroy temp The 'atomically set *this to other' is hard for shared_ptr because it stores two pointers, but not a problem for a single pointer implementation. operator=( atomic_ptr const & other ) is of course atomic_ptr temp( other ); this->assign( other ); What am I missing? .