Boost logo

Boost Users :

Subject: Re: [Boost-users] functor for boost::thread_group threads: which one is correct?
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-08-23 22:05:37


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.


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