Wait for the terminations of all children threads

  • Thread starter Thread starter Franz
  • Start date Start date
F

Franz

I use the following to let the calling thread to go forward after the
terminations of all the children threads.

for (int i=0; i<threadCount; ++i) {
threads.Join();
}

Is it a good strategy?
 
Yes if the main thread needs to wait for them all to finish. Depending on
many factors and bazaar things, a join like that could wait for ever on a
hung thread to quit. To be safe, always use some reasonable timeout value
and fail back to thread abort if the thead will not join or is not
processing its signal to stop (i.e. your internal bool, etc.)
 
Back
Top