dimanche 1 avril 2018

Stopping a currently running thread c++

I have a manager class that has created a thread for an execute method of a member.

 int Task::Execute()
    {
        try
        {
            setTaskSeqByName();
            for (int i = 0; i < mTaskSequence.size(); i++)
            {
                if(mCurrentStatus == "running")
                    mTaskSequence[i]->Execute();
            }
        }
        catch (std::exception ex)
        {
            return -1;
        }
        return 0;
    }

I would like to be able to run it a different thread so I would be able to execute a stop that will change the mCurrentStatus variable so the loop will stop as well as the mTaskSequence[i] task.

What is the best way to do so?

Thank you!

Aucun commentaire:

Enregistrer un commentaire