I have a program in which we can monitor 2 objects at same time.
myThread = new thread (thred1, id);
vec.push_back (myThread);
In thred1 function,i use Boolean function to read the stored values from a different vector and it runs parallely like this:
element found 2 -- hj
HUMIDITY-1681692777 DISPLAYED IN RH
element found 1 -- hj
TEMPERATURE--1714636915 IN DEGREE CELSIUS
This keeps on running as that is what my program should do. I have a case where I need to get ID from the user and stop that particular thread and the other should keep running till I stop it.Can someone help me with that?
void thred1 (int id) 
{
bool err = false;
    while (stopThread == false)
    {
    for (size_t i = 0; i < v.size (); i++)
        {
            if (id == v[i]->id)
                {
                cout << "element found " << v[i]->id << " -- " << v[i]->name << endl;
                v[i]->Read ();
                this_thread::sleep_for (chrono::seconds (4));
                err = true;
                break;
                }
        }
        if (!err)
        {
        cout << "element not found" << endl;
       break;
        }
    }
}
 
    