Subj : A question about atomic_ptr To : comp.programming.threads From : Peter Dimov Date : Sun Apr 10 2005 01:49 pm atomic_ptr (atomic-ptr-plus.sf.net), as most of you know, is Joe Seigh's strongly thread safe reference-counted smart pointer. My understanding (based on atomic_ptr.txt) is that it is intended to be used in the GC phase of the reader/writer problem as follows: atomic_ptr px; // shared object atomic_ptr read() { return px; // competing } void write() { lock(); atomic_ptr tmp( new X( *px ) ); // update *tmp px = tmp; // competing unlock(); } boost::shared_ptr can't be used in the above manner because of the two competing accesses that violate its "basic thread safety" requirement. However (again, if my understanding is correct), all atomic_ptr read accesses need to have acquire semantics, while shared_ptr read accesses need not. (local_ptr aside for a moment.) My question is: Can I get the best of both worlds by providing the following two methods in shared_ptr: template class shared_ptr { // ... shared_ptr copy() const; void replace( shared_ptr const & pt ); }; with the guarantee that competing accesses to 'copy' and 'replace' work (but other competing accesses are still disallowed in order to avoid an acquire except in 'copy')? -- Peter Dimov http://www.pdimov.com .