[cpp-threads] Weak vs Strong Atomics

Lawrence Crowl Lawrence at Crowl.org
Mon May 14 05:22:05 BST 2007


On 5/13/07, Roger Orr <rogero at howzatt.demon.co.uk> wrote:
> 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.

One of the requirements is to be able to make an arbitrary small
structured type atomic.  N2145 satisfies this requirement via the
generic type.  That is, you can write the following:

   atomic< pair< int, int > > variable;

I don't see how we'd do

   atomic_traits< pair< int, int >  >::type_name

without also introducing another generic type, which brings us
back to the separate types.

-- 
Lawrence Crowl



More information about the cpp-threads mailing list