Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Chris Thomasson Date : Mon Apr 18 2005 02:11 am > Hm. How about the following DWCASless algorithm: OK, this is similar to logic that I used a while back: http://groups.google.ca/groups?hl=en&lr=&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 ) ---------- obj_t *lptr; 1: inc gate 2: point lptr to new obj_t 3: xchg sptr with lptr 4: dec gate, if > 0 goto 6 5: dec lptr 6: done And they happen to execute like this: A1: gate = 1 | | B1: gate = 2 A2: lptr = new objB | | B2: lptr = objC | B3: sptr = objC && lptr = objA | B4: gate = 1 | B6: done A3: sptr = objB && lptr = objC A4: gate = 0 A5: dec objC A6: done Notice how Thread B leaked objA? .