Boost lzw wrote:
class group_helper { private: boost::shared_ptr<FileThread> m_object; public: group_helper() : m_object(boost::shared_ptr<FileThread>(new FileThread)) { std::cout << "group_helper::ctor called" << std::endl;} void operator()() { m_object->find(); m_object->print(); } ~group_helper() { std::cout << "group_helper::***dtor called" << std::endl; } };
int main() { group_helper gp; boost::thread_group threads; for (int i = 0; i < 1; ++i) threads.create_thread(gp); threads.join_all();
return 0; } =========== Output: 1 call to "group_helper::ctor called" 6 calls to "group_helper::***dtor called" =========== If the code is correct, does this mean that with thread_group we can no longer expect the # of ctors matches that of the dtors in threaded code?
It has nothing to do with threads, it's because you're not displaying calls to the copy constructor.