71b Subj : Re: A question about atomic_ptr To : comp.programming.threads From : Alexander Terekhov Date : Mon Apr 11 2005 03:47 pm Peter Dimov wrote: > > Alexander Terekhov wrote: > >>>> if ( ! atomic_dec_acquire( &shared_ptr::refs ) ) > > > > That must be upcoming Apple's OSAtomicDecrementRelAcq32() or > > OSAtomicDecrementSlbHsb32() (when X is immutable while managed > > by shared_ptr<>). ;-) > > Speaking of which, is it possible to implement the ...SlbHsb variant in a > more efficient manner on a PPC? SlbHsb version doesn't seem to need trailing isync, and maybe can achieve the effect of leading {lw}sync with respect to loads->store ordering using "branch never taken" trick. Consider: (excerpt from Book II) ---- B.2.3 Safe Fetch If a load must be performed before a subsequent store (e.g., the store that releases a lock protecting a shared data structure), a technique similar to the following can be used. In this example it is assumed that the address of the storage operand to be loaded is in GPR 3, the contents of the storage operand are returned in GPR 4, and the address of the storage operand to be stored is in GPR 5. lwz r4,0(r3) #load shared data cmpw r4,r4 #set CR0 to "equal" bne- $-8 #branch never taken stw r7,0(r5) #store other shared data ---- In our case, we load and check the count and do take a conditional branch which leads to stores which we want to order with respect to load and check. That's trailing isync. As for leading {lw}sync, we can add similar "branch never taken" trick to order it with respect to preceding loads, but I'm not sure whether register dependency (r4 for both load and compare above) can play some role here in addition to "branch never taken". regards, alexander. . 0