I am trying to implement multithreading in an application. An application needs to create a variable number of threads by passing variables. I can easily create threads, but I'm trying to figure out how to stop all threads at once, and if an error gets into any of these threads, stop them all.
My current solution is to enclose the functions in a loop that checks if the boolean is "True", in which case the flow continues. If there is an error, I change the value to "False", and all threads stop. Similarly, if I want to stop threads manually, I can set the value to false from the function.
Is there a better solution for this, since the main problem is that the threads must go to the end of the cycle before they stop completely?
source share