Reputation: 111
in c++ How can I stop or pause all other functions while this condition is met
else if (packet[0] == 0x5)
{
}
Basically I have a separate void function running a constant loop however if packet[0] ==0x5 i need it to stop all other threads (or pause)
Please and thanks Ant
Upvotes: 0
Views: 1285
Reputation: 613
In 'stdlib.h' there is a function exit(int Status_Code) which terminates execution of whole program. You should call exit(1) .
If you want only terminate that function just use return. e.g.
if(condition_met)
{
return;
}
Upvotes: 2
Reputation: 153955
I don't think there is a direct way to stop or pause other threads (other then stopping the entire program by exit(0)
). The only approach I'm aware of is a cooperative way where the threads which need to stop or pause are notified in some way and proactively act upon this notification. How the notification would look exactly depends largely on your system. One approach could be an atomic flag indicating that there is a need to act. If your threads supporting messaging, sending each one a message is probably more lightweight.
Upvotes: 2
Reputation: 414
Maybe put all those function calls into a thread, and when your realise you need to stop those functions, kill the thread
Upvotes: 0