Boost logo

Boost Users :

From: bill_kempf (williamkempf_at_[hidden])
Date: 2002-09-17 13:00:57


--- In Boost-Users_at_y..., Luis De la Parra <lparrab_at_g...> wrote:
> On Monday 16 September 2002 16:50, Marcio Del'Valle wrote:
> > Hi there,
> >
> > When I use boost::thread for creating multiple threads I notice
that the
> > destructor of object I pass as an argument ( boost::thread
(*pObjetc) ) is
> > called twice. Why does it happen?
>
> because boost makes a copy (acutally several!!) of the object, and
then
> destroys them. boost calls the copy constructor to get a copy of
the object
> you pass as a function object, and then makes another copy (don't
know why)
> and then destroyes the "temporary" objects.

This is documented. The number of copies made is left to the
implementation, but generally should be kept to a minimum. If you
don't want "pass by value" semantics use a wrapper/adapter such as
boost::ref.

Bill Kempf


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net