I m creating about 300 boost threads in a process. Is there any way to join a specific thread based on the thread id ?
It heavenly depends on how you save the boost::thread
s. If you save them in a container (with T = boost::thread*
), you can simply use something like
for(iterator it = ctn.begin(); it != ctn.end(); ++it){
if(it->get_id() == join_thread_id){
it->join();
break;
}
}
However, if you don't save your threads somewhere and just use new boost::thread
without saving the pointer it's not possible since boost doesn't provide any automatic bookkeeping functionality.
1. Remark: Keep in mind that you'll need to use boost::thread::id
to save the id.
2. Remark: std::map<boost::thread::id,boost::thread*>
might come in handy for such tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With