Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Joe Seigh Date : Thu Apr 14 2005 12:06 pm 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 think that you have a bug in your PPC implementation, but I may be missing > something. In inc_ref, you reload the pointer and check for change, however, > the pointer is a local function argument (int* refcnt) and will never > change. > > And you are right that Reinholz uses the same algorithm, except he passes an > int** (the offset hack aside). > > You're right, that's a bug. Good catch. It should be int **. I think I'll throw in a extra temp register. I don't trust GCC to form the memory operand for that correctly. As far as the offset goes, I hardcoded the offset in my version since I have a non-intrusive refcount and I control the format and there didn't seem to be an offset_of macro around. It's not really a finished version, just a pre-beta proof of concept so there's some quick and dirty stuff in it still. -- Joe Seigh .