[cpp-threads] Weak vs Strong Atomics

Roger Orr rogero at howzatt.demon.co.uk
Sun May 13 23:04:03 BST 2007


cpp-threads-bounces at decadentplace.org.uk wrote:

> There may be a misunderstanding of N2145 here.  There isn't a
> C-compatible level in the sense that I think you're talking
> about. The confusion make come from atomic_int and
> atomic<int>, and there is no difference here in operations or
> capability.  The only difference is a generic name versus a
> specific name. 

I was wondering about the generic name - could we use a traits class rather
than an atomic template?

Something like this:

template <typename T>
struct atomic_traits
{
};

template <>
struct atomic_traits<int>
{
   typedef atomic_int type_name;
};

(Etc for the other types.)

Or, given the strong/weak discussion we're having:

template <>
struct atomic_traits<int>
{
   typedef strong_atomic_int type_name;
   typedef weak_atomic_int weak_type_name;
};

Then generic code can use:

atomic_traits<T>::type_name value;

This mechanism would avoid introducing a separate set of atomic types.

Regards,
Roger.




More information about the cpp-threads mailing list