C++11 atomic library notes V2 - updated

Andrew MacLeod amacleod@redhat.com
Fri Oct 7 18:14:00 GMT 2011


After some discussions and further coding, the external library has been 
refined.

I've updated the document at http://gcc.gnu.org/wiki/Atomic/GCCMM/LIbrary

In a nutshell, the changes are:

1 - generic routines
=============
The generic version routines for arbitrary sized objects were 
unimplementable as stated. The new generic interface now works on a 
'slab of memory', and any required memory is passed in by the caller.

void __atomic_exchange (size_t obj_size_in_bytes, void *mem, const void 
*value, void *return_value, enum memory_model model)

and is utilized like:

template class <T>
T exchange (T *mem, T val, memory_order m)
{
   T tmp;
   __atomic_exchange (sizeof (T), mem, &val, &tmp, m);
   return tmp;
}

The compiler can recognize compile constants in the size parameter and 
map the call to one of the 5 built-in optimized sizes.  Optimization 
then folds away all the temporaries, address taken flags, and extra 
copies.  This has the added benefit of mapping structures of 8 bytes to 
an optimized built-in for 8 byte objects, which was missing before.

2- Volatiles.

http://gcc.gnu.org/ml/gcc/2011-10/msg00072.html  pretty conclusively 
demonstrates to me that the volatility of an object isn't grounds to 
segregate the implementation. As such, the library remains as originally 
stated with no mention of volatile versions or anything like that.

Andrew



More information about the Gcc mailing list