552 Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Peter Dimov Date : Sat Apr 16 2005 07:54 pm Joe Seigh wrote: > On Sat, 16 Apr 2005 15:52:09 +0300, Peter Dimov > wrote: >> But there's one other thing: shared_ptr is two pointers, not one. >> Without DWCAS, or at least double-wide atomic loads and stores, even >> hazards aren't enough to make it atomic. :-( > > Sounds like it's using separate refcount and object pointers to make > dereferencing the object less expensive, as opposed to keeping the > object pointer with the refcount which is what I do with atomic_ptr. It's > an implementation issue. It's also an interface issue; a separate pointer is needed for pointer conversions (shared_ptr to shared_ptr or shared_ptr). But if I place a limit of at most one writer... would I be able to get away with something like: l1: load pointer to object load pointer to count set hazard pointer fence compare pointer to object compare pointer to count compare hazard pointer if mismatch goto l1 ? Then l2: load count if zero goto l3 attempt to store count+1, goto l2 if not successful return (pobject, pcount) l3: set hazard pointer to zero scan hazards and deallocate count if not referenced return (NULL, NULL) ? . 0