|
Boost Users : |
Subject: Re: [Boost-users] Determining thread existence
From: Jeremy Rottman (rottmanj_at_[hidden])
Date: 2009-04-08 13:44:59
What I am trying to do is remove threads from the thread group after
they have run. So that when my daemon iterates it will start new threads
if none exist.
Here is my current code modified so that it will build without any extra
dependencies.
#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <sstream>
#include <string>
using namespace std;
int sayHello(int x){
cout << "Hello world from thread: " << x << endl;
return 0;
}
int main(int argc, char *argv[]) {
boost::thread_group Tg;
cout << "Thread Size Before: " << Tg.size() << endl;
for(int i = 1; i < 25; i++){
//dmParse parse;
//Tg.create_thread(boost::bind(&dmParse::onInit,parse,i));
Tg.create_thread(boost::bind(sayHello,i));
}
cout << "Thread Size: " << Tg.size() << endl;
Tg.join_all();
cout << "Thread Count After:" << Tg.size() << endl;
}
Nigel Rantor wrote:
> Jeremy Rottman wrote:
>> Anyone have any insight as to why these threads are not being
>> terminated? I have been doing a lot of different tests to determine
>> where it might be going wrong. And thus far, I have not been able to
>> find exactly where or why the threads will not join properly.
>
> [code that won't compile snipped]
>
> a) What makes you think that the threads aren't being terminated?
>
> b) It would be a lot more helpful if you provide code that compiles
> doesn't have dependencies others are unlikely to have.
>
> A full set of includes at the top would also have helped.
>
> After modifying your code I'm not sure what your problem is.
>
> join_all/interrupt_all will not remove threads from the thread group.
>
> n
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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