I have a random number of threads being generated and my main thread needs to act as a timer in a tight loop. I would like to check if the children threads ended and if so I want to break the tight loop. However, I haven't been able to find any way to do this without blocking.
My best idea has been to use a variable equal to the random number of threads that will be created. When a thread is about to complete it should decrement the variable. Meanwhile the main thread can quickly check the variable to see if it is greater than 0, if so keep looping.
There must be a better way, I hope.