Boost logo

Boost :

Subject: Re: [boost] [xint] Boost.XInt formal review (concrete complaint)
From: Ivan Le Lann (ivan.lelann_at_[hidden])
Date: 2011-03-07 03:45:02


Le lundi 07 mars 2011 à 02:21 -0500, Chad Nelson a écrit :
> 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.

I'm not sure I understand why you say that t does not get a shared copy.
Anyway what seemed obvious to me with current impl is that block below
can either leak or double destruct x data. Am I wrong?

void f (integer) {} // by value
...
{
  integer x = 42;
  async ( f, x );
  async ( f, x );
}
...

Ivan


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