From: thefed Date: 2008-01-01T02:56:39+09:00 Subject: Re: Why not call Thread.join? On Dec 31, 2007, at 11:15 AM, Robert Klemme wrote: > On 31.12.2007 17:02, thefed wrote: >> OK, I understand it better. But why does each {|t| t.join} join >> them all at the same time (ish), and not wait for the first one >> to finish executing before joining the others? > > They are not joined at the same time but one after the other. But then why doesn't this take 15 seconds? t.join is called in the main thread, so shouldn't the next Thread#join not get called until the first one finishes? module Enumerable def each_simultaneously threads = [] each { |e| threads >> Thread.new { yield e } } return threads end end start_time = Time.now [7,8,9].each_simultaneously do |e| sleep(5) # Simulate a long, high-latency operation print "Completed operation for #{e}!\n" end # Completed operation for 8! # Completed operation for 7! # Completed operation for 9! Time.now - start_time # => 5.009334