Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Chris Thomasson Date : Fri Apr 15 2005 08:12 pm > A non-tricky copy constructor cannot be made > race-resistant, no matter how I fiddle with the assignment. Here is a "tricky" way to increment a reference count wrt strong thread safety: < snippet from my library > static AC_INLINE void AC_APIDECL ac_i686_lfgc_refcount_load ( ac_thread_t *_tls, ac_i686_lfgc_refcount_t **pdest, ac_i686_lfgc_refcount_t **psrc ) { register ac_intword_t refs, refs_cmp; register ac_lfgc_smr_hazard_t hazard; register ac_i686_lfgc_refcount_t *src, *old = *pdest; /* grab tls and hazard pointer */ if ( ! _tls ) { _tls = ac_thread_self(); }; hazard = ac_lfgc_smr_get( _tls, 0 ); for( ;; ) { /* expensive smr load */ src = (ac_i686_lfgc_refcount_t*) ac_i686_lfgc_smr_activate ( hazard, (ac_i686_node_t**)psrc ); if ( ! src ) { break; } /* addref if greater than zero */ refs = src->refs; while( ( refs & 0x7FFFFFFF ) > 0 ) { refs_cmp = refs; refs = ac_atomic_cas_acquire ( &src->refs, refs_cmp, refs_cmp + 1 ); if ( refs == refs_cmp ) { /* we now own a reference to src */ ac_i686_lfgc_smr_deactivate( hazard ); goto ac_i686_lfgc_refcount_load_ok; } } } /* store src and release the old */ ac_i686_lfgc_refcount_load_ok: ac_mb_storeptr_release( pdest, src ); ac_i686_lfgc_refcount_release( old ); } If you want full source check out the following files my AppCore library uses: ac_i686.h ac_i686_lfgc_smr.h ac_i686_lfgc_refcount.h ac_smr.hpp ac_i686.c ac_i686_lfgc_smr.c ac_i686_gcc.asm http://appcore.home.comcast.net/appcore_4_1_2005.zip ( full source to AppCore. ) Any questions regarding my implementation of SMR and/or single-word atomic reference counting are welcome and encouraged... :) .