Boost logo

Boost :

From: Mac Murrett (mmurrett_at_[hidden])
Date: 2001-11-29 15:27:30


> Why? I don't see anything silly with the idea that an instance of class X is
> thread safe.

My point is that ints are thread-safe; it's operator++ that is not. Given
this, making another type to do what an int does (hold an integral value) in
thread-safe manor is not useful; it's the incrementation that is being made
thread-safe.

>> template<class Int>
>> void increment_atomic(Int &rValue);
>
> What are you going to (portably) do with this function? You don't know which
> 'Int', if any, works on the current platform.

Just specialization such as (for Windows):

template<>
void increment_atomic<long>(long &rValue)
{
    InterlockedIncrement(&rValue);
}

And then a general case. I do not believe that the general case can be made
to be suitably efficient and friendly, however, as it will require either a
mutex parameter or a map look-up, or possibly a mutex parameter that
defaults to a map look-up.

The other alternative is to have a specialization for a special type, and
have that type hold a mutex and an integer.

After more thought, however, I don't fully support this idea, although I
think that it is the best interface if we can find a suitable general-case
implementation.

Mac.


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