Re: [Boost-users] boost::thread Destructor being called multiple times
At 09:51 AM 8/25/2007, kaliwanagan wrote:
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Try defining an explicit copy constructor with a message like the others. I believe the issue is that your object is being passed by value, and being copied a few times along the way. You're not seeing your no-args constructor message because the other new instances are invoking the copy constructor.
On 25/08/07, Nat Goodspeed
At 09:51 AM 8/25/2007, kaliwanagan wrote:
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Try defining an explicit copy constructor with a message like the others. I believe the issue is that your object is being passed by value, and being copied a few times along the way. You're not seeing your no-args constructor message because the other new instances are invoking the copy constructor.
One way to avoid it might be using: void testBoostThread() { boost::thread thrd (boost::ref(testclass)); // pass testclass by reference thrd.join(); }
On Saturday 25 August 2007 23:46:53 Darren Garvey wrote:
On 25/08/07, Nat Goodspeed
wrote: At 09:51 AM 8/25/2007, kaliwanagan wrote:
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Try defining an explicit copy constructor with a message like the others. I believe the issue is that your object is being passed by value, and being copied a few times along the way. You're not seeing your no-args constructor message because the other new instances are invoking the copy constructor.
One way to avoid it might be using:
void testBoostThread() { boost::thread thrd (boost::ref(testclass)); // pass testclass by reference thrd.join(); }
Thanks for the guidance Darren, Nat (and gchen). I will be trying out your suggestions soon. Quite curious though, that the object passed by value to boost::thread was copied at least five times (if we go by the number of destructions taht took place). This is the first time I've seen boost::ref actually being useful XD I always thought it's easier to just create a pointer (or a reference) if I want to pass by reference. Thanks for introducing me to it.
On Saturday 25 August 2007 23:46:53 Darren Garvey wrote:
On 25/08/07, Nat Goodspeed
wrote: At 09:51 AM 8/25/2007, kaliwanagan wrote:
I was just curious as to why the class destructor are (apparently) being called multiple times. I have tried searching the archives to no avail (which prompted me to register and post to the mailinglist).
Try defining an explicit copy constructor with a message like the others. I believe the issue is that your object is being passed by value, and being copied a few times along the way. You're not seeing your no-args constructor message because the other new instances are invoking the copy constructor.
One way to avoid it might be using:
void testBoostThread() { boost::thread thrd (boost::ref(testclass)); // pass testclass by reference thrd.join(); }
Thanks, I just tried this and now it gives me saner destruction sequences :)
participants (3)
-
Darren Garvey
-
kaliwanagan@gmail.com
-
Nat Goodspeed