Boost logo

Boost :

Subject: Re: [boost] [atomic] Generalized read-modify-write operation
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2015-09-01 07:14:08


On 1 Sep 2015 10:35 am, "Andrey Semashev" <andrey.semashev_at_[hidden]> wrote:
>
> Hi,
>
> I was wondering is there would be interest in a generalized
> read-modify-write operation in Boost.Atomic.

Yes. At the very least it can cleanup some idioms if not make them faster.

[...]
> I know there's probably no way to ensure that the function meets these
> requirements, and it is possible to get an infinite loop in runtime,
> so maybe always using a CAS loop would be a safer approach, even on an
> architecture with LL/SC instructions.

The implementation could fall back on the CAS loop after the first failed
LL/SC. You might want to do it even in the case if contention to reduce the
window the cachelines must be held. It is not optimal in case that the
reservation always fail, but is always correct and the performance can be
corrected with profiling and some sort of CAS hint.

This is always possible because CAS must always be a valid implementation
strategy.

-- gpd


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk