On 1 Sep 2015 10:35 am, "Andrey Semashev"
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