Project

General

Profile

Bug #4283 ยป timeout-race-fix.patch

kosaki (Motohiro KOSAKI), 01/17/2011 01:53 PM

View differences:

lib/timeout.rb
return yield(sec) if sec == nil or sec.zero?
exception = klass || Class.new(ExitException)
begin
x = Thread.current
y = Thread.start {
begin
sleep sec
rescue => e
x.raise e
else
x.raise exception, "execution expired" if x.alive?
begin
x = Thread.current
y = Thread.start {
begin
sleep sec
rescue => e
x.raise e
else
x.raise exception, "execution expired"
end
}
return yield(sec)
ensure
if y
y.kill
y.join # make sure y is dead.
end
}
return yield(sec)
end
rescue exception => e
rej = /\A#{Regexp.quote(__FILE__)}:#{__LINE__-4}\z/o
(bt = e.backtrace).reject! {|m| rej =~ m}
......
raise if klass # if exception class is specified, it
# would be expected outside.
raise Error, e.message, e.backtrace
ensure
if y and y.alive?
y.kill
y.join # make sure y is dead.
end
end
end
    (1-1/1)