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).
#include
struct TestingClass
{
TestingClass()
{
std::cout << "constructor called" << std::endl;
}
~TestingClass()
{
std::cout << "destructor called" << std::endl;
}
void operator()()
{
std::cout << "operator() called" << std::endl;
}
} testclass;
void testBoostThread()
{
boost::thread thrd (testclass);
thrd.join();
}
int main ()
{
testBoostThread();
return 0;
}
The output:
constructor called
destructor called
destructor called
destructor called
destructor called
operator() called
destructor called
I would appreciate if someone can enlighten me on this. Will having
the destructor called multiple times be a cause of concern? Will it
cause some undefined symptoms? Is there a way to completely avoid this
situation?