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 12:24:42


----- "Chad Nelson" <chad.thecomfychair_at_[hidden]> a écrit :

> On Mon, 07 Mar 2011 09:45:02 +0100
> Ivan Le Lann <ivan.lelann_at_[hidden]> wrote:
>
> >>> 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 );
> > }
>
(snip)
> Unless you
> explicitly tell the library to use CoW on external objects, it will
> deep-copy them, so each call to async will get its own storage.
>

Ohhh ... I only get now what you meant with "external objects".
I forgot you have only limited COW. Sorry for my slow brain.

This might explain why XInt was significantly faster when I added
byref arguments. I exspected marginal speedup and got 30%.

Ivan


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