From: Michael Boutros Date: 2008-07-15T03:03:18+09:00 Subject: Re: Ruby & Threads Joel VanderWerf wrote: > Michael Boutros wrote: >> puts "Starting #{number}...\n" >> sleep(5) >> holder << number >> end >> end >> end >> >> @thread.join > > #join is definitely a good idea, because otherwise (as you observed) the > main thread will exit before the others have finished, but you are > overwriting the @thread variable on each iteration through the loop. > > The usual idiom for this is something like: > > threads = array.map { Thread.new {...} } > threads.each {|th| th.join} Joel, Initially I meant to do that because I thought that I would only need to "join" one thread to get them all to continue, until I realized that some might finish before others, so I altered the code to the method that you described. -- Posted via http://www.ruby-forum.com/.