diff --git a/lib/timeout.rb b/lib/timeout.rb
index 297b769..a478720 100644
--- a/lib/timeout.rb
+++ b/lib/timeout.rb
@@ -40,11 +40,13 @@ module Timeout
   # Note that this is both a method of module Timeout, so you can 'include Timeout'
   # into your classes so they have a #timeout method, as well as a module method,
   # so you can call it directly as Timeout.timeout().
-  def timeout(sec, klass = nil)   #:yield: +sec+
+  def timeout(sec, klass = nil, &block)   #:yield: +sec+
     return yield(sec) if sec == nil or sec.zero?
     exception = klass || Class.new(ExitException)
     begin
-      x = Thread.current
+      x = Thread.start {
+        block.call(sec)
+      }
       y = Thread.start {
         begin
           sleep sec
@@ -54,7 +56,8 @@ module Timeout
           x.raise exception, "execution expired" if x.alive?
         end
       }
-      return yield(sec)
+      x.join
+      return sec
     rescue exception => e
       rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
       (bt = e.backtrace).reject! {|m| rej =~ m}
