In my application I have a callback and, if a certain event happens, it has to perform certain operations.
void callback()
{
if(event == true)
{
// long processing
performOperations();
}
}
Now, the thing is that the callback is called at a 30Hz rate, while the performOperations
function can take also ~10 seconds to complete.
After a quick search online I came across std::async. The strategy I want to implement is that if the performOperations
is running and a new event
happens I want to "kill" (stop nicely) the running thread and start a new one which still launches the performOperations
function.
So, something like this:
void callback()
{
if(event == true)
{
// check if there's a running thread
if(already_running == true)
{
// stop nicely the running thread
...
}
// long processing
performOperations();
}
}
Therefore, my question. Is there a way to know that performOperations
is still running and kill it?
Thanks