[cpp-threads] Re: Increment/decrement operators on atomics package
Lawrence Crowl
Lawrence at Crowl.org
Fri Apr 20 13:45:07 BST 2007
On 4/20/07, Raul Silvera <rauls at ca.ibm.com> wrote:
>
> Lawrence, something that we briefly touched on in Oxford was the question of
> increment operators in the atomics package doing a RMW operation.
>
> I think that it is in generally confusing for t+=1 and t=t+1 to have
> different semantics for an Atomic t. The difference would be that t+=1 would
> be RMW operation while t=t+1 is a sequence of
> load_acquire;add;store_release.
> The main concern is that users consider these two idioms interchangeable and
> replace one by the other only based on programming style.
Note that this transformation is not semantically neutral in the absence
of atomics. f()+=1 is not equivalent to f()=f()+1.
> My proposal for this issue is to make t+=1 have the same semantics as t=t+1
> (no RMW). Instead, a separate member functions would be provided to do RMW
> operations (e.g t.atomic_inc(1)).
> An alternative proposal would be not to define increment operators for the
> atomic class.
>
> Do you consider this a valid concern? Thanks...
I consider it a valid concern, . The choice, I think is between the notational
convenience of += and the education of the users. Given that using atomic
will take substantial education anyway, I fell on the side of notational
convenience. If there is a consensus to remove the operator, I think that
the same reasoning applies to ++ operators.
--
Lawrence Crowl
More information about the cpp-threads
mailing list