393 Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Peter Dimov Date : Mon Apr 18 2005 12:23 pm Chris Thomasson wrote: >> Hm. How about the following DWCASless algorithm: > > OK, this is similar to logic that I used a while back: > > http://groups.google.ca/groups?selm=R6fmb.18865%24Fm2.9642%40attbi_s04 > > You could run into a similar race-condition described. Your algorithm > could cause a memory leak: > > Think if the following scenario occurred: > > > > > static obj_t *sptr = new objA; > > > Threads A and B - ( both writers ) The algorithm was single writer, multiple readers, but it's still wrong. :-( Reader r1 inc gate, read pointer Writer w inc gate, replace pointer Reader r2 inc gate, read new pointer Reader r1 dec gate, do nothing (!= 0) Writer dec gate, do nothing (!=0) Reader r2 dec gate, do nothing (pointer hasn't changed) . 0