Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

making a thread wait  RSS feed

 
Gamb Rockwell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you make a parent thread wait for all threads that it has created and are still running.

thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the "join" method, in a loop, like

 
Bryan Lee
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Group the threads created by the parent... then,

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by shiningliao:





Note that on many architectures, this loop will consume 100% CPU. The join() method is specifically intended to wait until a Thread completes; it does a good job, as it waits without consuming any CPU time at all. In general, one should always prefer the "right" way to do things instead of some made-up way.
 
Bryan Lee
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Note that on many architectures, this loop will consume 100% CPU.


Thanks for point out the problem. I did that on WinIA32 and didn't realize
the potential problem on different architectures.

Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!