title: Ruby thread fatal deadlock error
body: <p>I have this simple ruby code:</p>
  
  <pre><code>require 'rubygems'
  require 'Thread'
  
  
  queue = Queue.new
  
  t = Thread.new do
    loop do
      user = queue.pop
  
      puts "Unqueued #{user.nickname}, running all scripts..."
  
      #do stuff
      user.run_all
  
      puts "Finished running all script for  #{user.nickname}, sleeping for 2"
      sleep 2
  
      queue &lt;&lt; user    
    end
  end
  
  t.join
  </code></pre>
  
  <p>When I try to run it, it gives me this error:</p>
  
  <pre><code>deadlock 0x10ec549f0: sleep:-  - ./Machine.rb:9
  deadlock 0x10ea46348: sleep:J(0x10ec549f0) (main) - ./Machine.rb:23
  fatal: Thread(0x10ea46348): deadlock
      from ./Machine.rb:23:in `join'
      from ./Machine.rb:23
      from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
      from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
      from (irb):1
  </code></pre>
  
  <p>What am I doing wrong?
  Thanks</p>