Subj : Re: std::msync To : comp.programming.threads From : Alexander Terekhov Date : Sat Apr 02 2005 05:07 pm Peter Dimov wrote: > > Alexander Terekhov wrote: > > bool lock() throw() { > > return use_count_.increment_if_not_min(); // naked > > } > > msync::naked_competing, IIUC? Yep. > Is cmpxchg on x86 a proper implementation of > naked_competing, or does it need a lock prefix? Without a lock it is naked_MP_noncompeting so to speak. Without a lock it isn't atomic with respect to other processors (and probably HT threads, cores, etc.) at all AFAIK. > And if lockless cmpxchg is > fine, It might work on a uniprocessor or then all potentially contending thread are bound to the same processor. > > > void add_ref() throw() { > > use_count_.increment(); // naked > > } > > should this use cmpxchg too instead of lock inc/lock xadd? Given that cmpxchg without lock is MP unsafe, lock inc/lock xadd is probably beter. regards, alexander. .