[cpp-threads] modes, pass 2

Doug Lea dl at cs.oswego.edu
Mon May 9 13:43:07 BST 2005


Peter Dimov wrote:
> Alexander Terekhov wrote:
> 
>>Fallible CAS can be used in unlock(), but what about reduntant loads
>>(in the case of CAS-based variation) in lock()?
> 
> 
> The redundant load will always hit the L1 cache. The perf hit is negligible. 
> B.4 even says that "in some implementations, better performance may be 
> obtained by using a regular Load to do the initial checking."
> 
> The other examples aren't expressible with CAS, though. 
> 
> 

One common idiom here is: Don't bother with the SC if
the LL got any of several values you don't like. As opposed to CAS that
only tests one likeable value. This is indeed one of the strengths
of LL/SC vs CAS. On the other hand, the more cycles you put between
the LL and SC the less likely it is to work, and my impression (just
an impression) is that the curve drops steeply, so I wonder whether
any of these are actually faster on MP PPC implementations.

(Also, maybe there's a good CAS-based emulation for this idiom?
I don't know one offhand.)


-Doug




More information about the cpp-threads mailing list