Boost logo

Boost :

Subject: Re: [boost] [atomic] Generalized read-modify-write operation
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2015-09-01 19:20:14


On 1/09/2015 21:35, Andrey Semashev wrote:
> I was wondering is there would be interest in a generalized
> read-modify-write operation in Boost.Atomic. The idea is to have a
> atomic<T>::read_modify_write method that would take a function that
> would perform the modify on the atomic value. The interface could be
> roughly this:
[...]
> Does this look interesting to anyone? Comments?

It's not strictly necessary since it's equivalent to a do { r =
modify(n); } while (!var.compare_exchange_weak(n, r, order)) loop, which
isn't that much more typing. (Although I elided the initial load, so
it's a bit more typing than it appears here.)

(And the above is also supposed to use LL/SC on architectures where this
is cheaper than CAS, although I'm not sure if this is the case.)

But provided that the code generated is no worse than this (in
particular that the compiler can inline the function call in optimised
builds, at least where the function is relatively simple) then it would
still be useful, particularly for people who aren't used to using weak
exchange loops.


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