Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-29 10:40:35

From: <williamkempf_at_[hidden]>
> --- In boost_at_y..., "Peter Dimov" <pdimov_at_m...> wrote:
> > Raw integers are completely thread safe when there is only one
> thread. ;-)
> No, they're not. The program is safe from race conditions by the
> fact that there's only one thread, but that doesn't make the integer
> thread safe. I realize you know this (that's why you've got the
> smiley), but I think it's important to state this. It's very
> important to not do ANYTHING that gives the niave programmer the idea
> that integral types are thread safe. They turn out to be enough of
> the time to likely lead such a niave user into thinking they always
> are. That's one reason I don't like the integer arithmetic operators
> being used for increment and decrement of a thread safe counter. The
> other is that the operations suggest functionality that doesn't exist
> (such as post-fix versions, other integer operations or even just an
> assumption on the return type).

Valid points. However every programmer needs to realize, sooner or later,
that when the specification of type X says that ++x may return void, then it
really may return void and the return value should not be used; and that
having a preincrement doesn't necessarily imply a postdecrement unless it's

Having built-in integers meet the AtomicCount requirements has its benefits.
It's not the only option but atomic_count's audience aren't really the naive

Peter Dimov
Multi Media Ltd.

Boost list run by bdawes at, gregod at, cpdaniel at, john at