Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-08-30 17:44:58


From: Dietmar Kuehl <dietmar_kuehl_at_[hidden]>
> William Kempf wrote:
>
> > Possible interface:
>
> First of all, I'm in favour of such an interface using function on an
> opaque type. A possible variation might be the use of traits-like
> approach: Since there is only one dimension of variation (the
> atomic type) it is not necessary to have the functions as non-member
> functions. Thus, something like this might be more in order:
>
> atomic_traits<atomic_t>::increment(val)
> atomic_traits<atomic_t>::decrement(val)
> ...
>
> > typedef ... atomic_t;
> > long increment(atomic_t& dest);
> > long decrement(atomic_t& dest);

In the past I have used a class with overloaded operator++ and operator--.

> I can see uses for these three, eg. a referenced counted entity.
>
> > long add(atomic_t& dest, long value);
> > long add(atomic_t& dest, const atomic_t& value);
> > long exchange(atomic_t& dest, long value);
> > long exchange(long& value, const atomic_t& value); // Note 1
> > long compare_exchange(atomic_t& dest, long compare, long value);
>
> ... but I have no idea what this stuff might be used for. Unless there
> are
> important uses of the more advanced features, I would prefer to stick
> with the bare minimum of functionality which are atomic increment
> and decrement functions. If there are usage patterns for the other
> features, I would divide them into concepts: I can imagine platforms to
> have native support for efficient increment and decrement but not for
> the others. Requiring the more advanced features would unnecessarily
> burden these atomic integers.

I agree.
 
> Can you please outline where the other features are necessary?

You can do interesting tricks, like a stack with atomic push and pop
operations but no mutex. Nice for managing the free list in a
memory allocator.

> I assume it is a lost battle to bring up again that this stuff seems to
> be at a too low level of abstraction for now: I still haven't seen the high
> level entities which are implemented using these low-level features...

We have long needed atomic_decrement for making shared_ptr
thread safe.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk