boost::thread maybe have bug.
Recently, I download boost 1.31.0 and compile it with Visual studio.net 2003. But the code below can't work properly: class A { public: A() { printf("constructor.\n"); } ~A() { printf("destructor.\n"); } void operator () () { } }; int main(int argc, char* argv[]) { A a; boost::thread t(a); t.join(); } In my system, it generate the message like this: D:\thread\Debug>thread.exe constructor. destructor. destructor. destructor. destructor. destructor. destructor. Who can tell me what's wrong with boost or something else? -- Ride tricycle around the world.
On Nov 3, 2004, at 10:28 AM, 蹬三轮的 wrote:
Recently, I download boost 1.31.0 and compile it with Visual studio.net 2003. But the code below can't work properly:
class A { public: A() { printf("constructor.\n"); }
~A() { printf("destructor.\n"); }
void operator () () { } };
int main(int argc, char* argv[]) { A a; boost::thread t(a); t.join(); }
In my system, it generate the message like this: D:\thread\Debug>thread.exe constructor. destructor. destructor. destructor. destructor. destructor. destructor.
Who can tell me what's wrong with boost or something else?
The A object is being copied several times. Add in a constructor like this to see what is going on: A(const A&) { printf("copy constructor.\n"); } If you really don't want copying to occur, use: boost::thread t(boost::ref(a)); Doug
I think boost makes a copy of the object (i'm sure someone else will
confirm/shoot this down), though I'm not sure if it would cause that.
try passing a boost::ref?
On Wed, 3 Nov 2004 23:28:56 +0800, 蹬三轮的
Recently, I download boost 1.31.0 and compile it with Visual studio.net 2003. But the code below can't work properly:
class A { public: A() { printf("constructor.\n"); }
~A() { printf("destructor.\n"); }
void operator () () { } };
int main(int argc, char* argv[]) { A a; boost::thread t(a); t.join(); }
In my system, it generate the message like this: D:\thread\Debug>thread.exe constructor. destructor. destructor. destructor. destructor. destructor. destructor.
Who can tell me what's wrong with boost or something else?
-- Ride tricycle around the world. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Cory Nelson http://www.int64.org
participants (3)
-
Cory Nelson
-
Doug Gregor
-
蹬三轮的