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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top