Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join a specific boost thread

I m creating about 300 boost threads in a process. Is there any way to join a specific thread based on the thread id ?

like image 739
sri Avatar asked Dec 19 '12 11:12

sri


1 Answers

It heavenly depends on how you save the boost::threads. 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.

like image 122
Zeta Avatar answered Oct 12 '22 12:10

Zeta