title: How can I kill a ruby thread after a certain amount of time?
body: <p>I want a thread that I create to die if it doesn't finish after a certain amount of time. Is there any elegant and/or idiomatic way to do this? Right now I am thinking to make a watcher thread:</p>
  
  <pre><code>def myfunc
    t = Thread.new{
      #do stuff
    }
  
    # watcher thread
    Thread.new{
      result = t.join(20) # join returns nil if it timed out
      t.kill if result.nil?
    }
  
    # continue on asynchronously from both threads
  end
  </code></pre>