title: Getting Thread not to run until join in ruby
body: <p>I am getting into ruby and have been using threads for a little while now with out fully understanding them. I notice that when adding a thread to an array and if I add a sleep() command as the first command the thread does not run until I do a join which is mostly what I want. So I have 2 questions.</p>
  
  <p>1.Is that suppose to happen?</p>
  
  <p>2.Is there a better way to do that other then the way I'm doing it. Here is a sample code that I have to show what I'm talking about.</p>
  
  <pre><code>job = Array.new
  10.times do |n|
      job &lt;&lt; Thread.new do
          sleep 0.001
          puts "done #{n}"
      end 
  end
  #job.each do |t|
      #t.join
  #end
  
  puts "End of script"
  </code></pre>
  
  <p>Output is </p>
  
  <pre><code>End of script
  </code></pre>
  
  <p>If I remove the comments output is  </p>
  
  <pre><code>done 1  
  done 0  
  done 7  
  done 6  
  done 5  
  done 4  
  done 3  
  done 2  
  done 9  
  done 8  
  End of script
  </code></pre>
  
  <p>So I use this now but I don't understand why it does that. Sometimes I notice even doing something like `echo hi` instead of sleep does the trick. </p>
  
  <p>Thanks in advance. </p>