Boost logo

Boost :

From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2004-09-20 06:40:52


On Mon, 20 Sep 2004 14:25:46 +0300, Peter Dimov <pdimov_at_[hidden]> wrote:
>
>
> Matt Hurd wrote:
> >> Peter Dimov <pdimov_at_[hidden]> wrote:
> >>> Matt Hurd wrote:
> >>> I'm interested in getting something like "needs_lock" below into the
> >>> normal traits, perhaps as part of boost thread. It informs you
> >>> whether of not an operation on such a contiguous block needs a lock
> >>> to be atomic.
> >>>
> >>> For example, on ia32 32 bit aligned ops are atomic, on ia64 it is 64
> >>> bit. doubles on ia32 need locking to be atomic, on ia64 they don't.
> >>
> >> What do you mean by "atomic"? Do you expect the change to the value
> >> to be visible to other threads?
> >
> > Just memory consistent / atomic. That is, if you write to memory or
> > read from memory all the bits will be guaranteed to make it as an
> > indivisible unit. It doesn't say anything about the timing of the
> > visibility or ordering w.r.t. like memory transactions.
>
> How would you use such a thing? :-)

My main current use is in a macro I use than generates getter and
setters with and without locking for simplifying the construction
concurrent aware classes.

So if it boost::needs_lock<T> for the type of the attribute it will
lock, otherwise it goes phew if I'm running on a Pentium 4 I probably
just saved a couple of hundred cycles and doesn't lock.

matt.


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