Subj : Re: std::msync To : comp.programming.threads From : Alexander Terekhov Date : Sat Apr 02 2005 05:29 pm Peter Dimov wrote: > > Alexander Terekhov wrote: > > class sp_counted_base { > > /* ... */ > > typedef refcount count; > > count use_count_, self_count_; > > /* ... */ > > public: > > /* ... */ > > sp_counted_base() : use_count_(1), self_count_(1) { } > > > > void add_ref() throw() { > > use_count_.increment(); // naked > > } > > > > bool lock() throw() { > > return use_count_.increment_if_not_min(); // naked For the record, naked was wrong here. It shall be msync::hsb (in min case) to impose ordering with respect to relaxed self_count_.decrement() in weak_release() below which doesn't do msync::rel. Or it can be naked, but then self_count_.decrement() in weak_relase() must have at least msync::slb (when result is not min). > > } > > > > void weak_add_ref() throw() { > > self_count_.increment(); // naked > > } > > > > void weak_release() throw() { > > if (!self_count_.decrement(msync::acq, count::may_not_store_min)) > > destruct(); > > } > > > > void release() throw() { > > if (!use_count_.decrement()) { // "full" release-acquire protocol > > dispose(); > > if (!self_count_.decrement(msync::rel, count::may_not_store_min)) > > destruct(); > > } > > } > > Question: your labeled approach only maps well to IA64 (and to a lesser > extent x86), right? It's an "extension" of conventional release consistency model. Revised Java, for example, also uses variation of release consistency model. But they use way too constrained variation AFAICS. > > On platforms with bidirectional fences, could it be possible for the labeled > approach to produce suboptimal code? I don't think so. Unidirectional labels don't preclude use of fences. Itanic does have "mf" after all. Unidirectional labels are simply better when you don't need bidirectional fences. And you rarely need bidirectional fences. > IOW can the algorithm above be improved > if it's known that the target platform has bidirectional fences and does not > support labels? I have yet to see such an algorithm... regards, alexander. .