Boost logo

Boost Users :

Subject: [Boost-users] thread group
From: Lloyd Kanakkassery (lloydkl.tech_at_[hidden])
Date: 2010-11-29 05:52:03


Hi,
I am creating "n" number of thread in a loop like this.
for(int i=0;i<n;++i)
{
    boost::shared_ptr<boost::thread> th(new
boost::thread(boost::bind(&Enum::Execute,shared_from_this(),i,x)));
}

How can I join all these threads?

The approach I used is given below...

Before the loop I have created a thread_group object

boost::thread_group tg;
for(int i=0;i<n;++i)
{
    boost::shared_ptr<boost::thread> th(new
boost::thread(boost::bind(&Enum::Execute,shared_from_this(),i,x)));
    tg.add_thread(th.get());
}
tg.join_all();

But the threads are not joined, it is exiting without completion. What could
be the mistake I am doing?

Thanks,
  Lloyd



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