Boost logo

Boost Users :

From: kaliwanagan (kaliwanagan_at_[hidden])
Date: 2007-08-25 09:51:33


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 <boost/thread/thread.hpp>

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?


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