[cpp-threads] Re: Increment/decrement operators on atomics package

Raul Silvera rauls at ca.ibm.com
Fri Apr 27 16:35:22 BST 2007


"Boehm, Hans" <hans.boehm at hp.com> wrote on 04/23/2007 07:39:33 PM:

> > 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.
> > 
> I actually have no idea which one would be more error prone for 
> uneducated users.  My impression (backed up by very limited 
> experience) is that the more naïve users may be surprised if you 
> tell them that any of the above, even t = t + 1, is NOT atomic. 
> Thus my inclination would be to follow the rule that any operations 
> on atomics that reasonably could be atomic, should be.
> 
> Hans

I hope you're not suggesting to make t = t + 1 a RMW operation. There
are many reasons why that is not feasible. The most we could do is
outlaw it in favor of using named member functions to access/modify
the variable, as Roger proposed on another note. However, if we were
to do that, we probably should outlaw += and ++ operators as well.

I believe it is simpler to teach the programmer that none of the implicit
operations have RMW semantics, rather than have a subset of them be 
RMW operations. From the programmer point of view, such a subset would
be arbitrary. 

If we keep the semantics of these operators as currently proposed, I
foresee us getting into situations where we have to tell users:
"there is a problem in your program, and to fix it replace x=x+1 with 
x+=1".
I think that would be highly undesirable.

Also, note that RMW operations are orders of magnitude more expensive than
regular accesses in pretty much all architectures. In some platforms they 
may
require acquiring a lock. So I believe the programmer should make it 
explicit
whether RMW semantics are required for each specific operation.

--
Raúl E. Silvera         IBM Toronto Lab         Team Lead, Toronto 
Portable Optimizer (TPO)
Tel: 905-413-4188       T/L: 969-4188           Fax: 905-413-4854 
D2/KC9/8200/MKM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.decadentplace.org.uk/pipermail/cpp-threads/attachments/20070427/e12b2360/attachment.html


More information about the cpp-threads mailing list