[concurrency-interest] Unsafe.getAndAddLong

Nathan Reynolds nathan.reynolds at oracle.com
Thu May 22 13:51:23 EDT 2014

I am curious.  How much does the load barrier cost?  The CAS can't 
execute until the load completes anyways.  In other words, there is a 
data dependency there.


On 5/22/2014 10:40 AM, Andrew Haley wrote:
> On 05/22/2014 05:44 PM, Nathan Reynolds wrote:
>> A CAS retry can be very costly.  See this blog entry for the details.
>> https://blogs.oracle.com/dave/entry/atomic_fetch_and_add_vs
>> Basically, as CAS retries happen more often the branch predictor will
>> predict that the loop will be re-executed.  So, when the CAS finally
>> succeeds, the processor will stall because the branch was predicted the
>> wrong way.  If CAS was used to acquire a lock, then the critical region
>> of the lock is now longer and throughput will suffer.
>> Word tearing is probably not very common.  But, an already hot CAS loop
>> wouldn't appreciate any more problems.
> Sure, but the problem is that already hot CAS loop has an unnecessary
> barrier, and that's not a rare case, that's every time.
> Andrew.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20140522/646d3ca6/attachment.html>

More information about the Concurrency-interest mailing list