[concurrency-interest] The very best CAS loop

Andrew Haley aph at redhat.com
Mon Sep 26 13:15:38 EDT 2016


On 26/09/16 18:01, Martin Buchholz wrote:
> My goals were to
> - have the shortest code path if the CAS succeeds the first time, which is
> hopefully the common case
> - never call the update function multiple times in the case of spurious
> failure, only for real contention.  We don't know how expensive the update
> function is, and the number of times it is called is user-detectable.

That's probably suboptimal.  The ratio of truly spurious failures
(caused by e.g pre-emption) to actual contention is probably pretty
small, so if a SC fails it's probably ture contention, and the value
in memory really has changed.  In that case Aleksey's version is
better.

It's impossible to tell for sure because it depends on your actual
contention rate in your application.

Andrew.


More information about the Concurrency-interest mailing list