Hi!
The thread function object is copied internally. The problem here is that
compiler creates default copy ctor and default assignment operator, which do
not output Constructor called... Or Assignment Operator called...
According to boost::threads the thread object must be copy-constructible. It
is better not to use heap, since the object is copied anyway and since your
object is a lightweight object (object without any non-static fields is 1
byte big) the copy operation is done very quickly.
Best Regards,
Ovanes
-----Original Message-----
From: elconio@commonworld.info [mailto:elconio@commonworld.info]
Sent: Saturday, October 07, 2006 17:02
To: boost-users@lists.boost.org
Subject: [Boost-users] [Thread] destructor called several times
Hello,
I am using boost::thread for a program, but it behaved in an unexpected way
(to me at least). I extracted a small case that shows my problem.
I searched in the archives and in the docs, but I couldn't figure this out.
With the following code [1] I expect the constructor of my the class
MyThread to be called only once and yet on my machine it is called 11 times!
[2] The problem is that I was freeing some ressources from the destructor
and that even before the operator() was called sometimes.
I am using the CVS version from 3 days ago on a linux x86.
Thanks for any help or any pointer !
[1]:
#include <iostream>
#include