Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review (concrete complaint)
From: Chad Nelson (chad.thecomfychair_at_[hidden])
Date: 2011-03-07 02:21:23


On Mon, 7 Mar 2011 04:37:40 +0200
"Peter Dimov" <pdimov_at_[hidden]> wrote:

> Chad Nelson wrote:
>> The only concrete complaint that people could give me about CoW was
>> that code using it couldn't be made thread-safe, which is true. So I
>> made a way to instruct the library to force all integer objects to
>> have unique storage before they're returned to user code, and made it
>> the default to prevent unpleasant client-code surprises.
>
> I don't think that this is enough to prevent surprises. If someone
> does
>
> thread t( f, x );
>
> where x is an integer, the thread would receive a shared copy of x.
> The user would need to explicitly call the copy constructor with a
> second argument of true to avoid that.

You'd think so, but so long as that thread class takes the integer
parameter as either a constant reference or by value, or is the only
one thread accessing it if it's passed by non-constant reference, that's
not the case. The copy constructor will automatically deep-copy the
object, unless the client code explicitly tells it to use external
copy-on-write -- that's the only time the second argument to the copy
constructor would come into play.

> Just use detail::atomic_count until C++0x atomics arrive in
> numbers. :-)

Not sure where I'd find detail::atomic_count. Has Boost.Atomic been
accepted? I don't see it in the 1.46 docs.

-- 
Chad Nelson
Oak Circle Software, Inc.
*
*
*



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