[cpp-threads] Should atomic_add support pointers?

Doug Lea dl at cs.oswego.edu
Sun Nov 6 20:31:50 GMT 2005


Peter Dimov wrote:
> I'm trying to nail down the semantics of an atomic ops library and I 
> encountered the following interesting issue:
> 
> Should atomic_add support pointer addition? That is:
> 
> int * p;
> 
> atomic_add( &p, 4 ); // allowed? sensible?
> 
> What do you think?
> 

In
   atomic_add( &p, 3 );
would the "3" mean 3 or does it mean 12 = 3 * sizeof(int)?
(Either way seems defensible.)

Also I suspect that people like Maged Michael who use marked-pointers
a lot would like to be able to do:
    atomic_or(&p, (intptr_t)1);
    atomic_and(&p, ~(intptr_t)1);

-Doug





More information about the cpp-threads mailing list