Boost logo

Boost Users :

Subject: [Boost-users] How to terminate a specific thread among other threads
From: Master (master.huricane_at_[hidden])
Date: 2012-04-15 08:19:29


Hello all .
i have been trying to selectively dispose a thread among some other threads
, but so far i wasnt successful in finding a way to do it .
suppose i have a simple function which identifies any threads which gets
into it and if a specific one is located ,it is disposed .
simply sth like this :

#include <boost/signal.hpp>
#include <iostream>
#include <boost/thread.hpp>
using namespace std;
boost::thread threadarray[3];

int t(int x)
{
    boost::id id();
    switch(boost::this_thread::get_id())
    {
    case threadarray[0].get_id():
        cout<<"thread 1";
        break;
        case threadarray[1].get_id():
       * DISPOSE THIS THREAD or CHANGE OWNERSHITP, OR GET ANOTHER JOB TO
IT , OR CHECK IF IT WAS SUCCESSFUL OR NOT*
        break;
        case threadarray[3].get_id():
        cout<<"thread 3";
        break;
        default:
            cout<<"default";
    }
    return 0;
}

int main()
{
    boost::thread t1(t,5), t2(t,6),t3(t,7);

    threadarray[0] = t1.move();
    threadarray[1] = t2.move();
    threadarray[2] = t3.move();

    for(int i = 0; i <3;i++)
    {
        threadarray[i].join();
    }
    system("pause");
}

i cant either use a switch statement to identify which thread im dealing
with at the moment , nor can i find any means to keep track of my threads ,
and manage them in situations like this ( i already tried
vector(boost::thread> my vect; and tries to use
std::for_each(vect.begin(),vect.end(),somefunction_accepting boost::thread)
, this doesnt work !! )

any idea how i can achieve sth similar?

Thanks in advance



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