Project

General

Profile

Actions

Backport #915

closed

threadのQueue#popでまっているときにTimeout.timeoutによるタイムアウトが発生したあとQueue#pushでささる

Added by kouji (Kouji Takao) almost 16 years ago. Updated over 13 years ago.


Description

=begin
thread の Queue#pop でキューへの追加をまっているときに、
Timeout.timeout によるタイムアウトが発生したときの挙動がrubyのバージョンによって異なり、
以下のようになりました。

  • 1.8.5 と 1.9 は同じ
  • 1.8.6 と 1.8.7 は同じ
  • 1.8ブランチの最新(r20895) はどれとも違う

なお、動作を確認した環境は Debian GNU/Linux 4.0(Etch) です。

----- timeout.rb: ここから -----
require "timeout"
require "thread"

queue = Queue.new
t = Thread.start {
begin
sleep(1000)
rescue Exception
end
}

begin
Timeout.timeout(2) do
puts "waiting pop..."
queue.pop
end
rescue Timeout::Error
p $!
end

puts "pushing..."
queue.push(1)
puts "pushed."

puts "poping..."
p queue.pop
puts "poped."

t.raise(Exception)
t.join
----- timeout.rb: ここまで -----

----- 実行結果: ここから -----
havana$ ruby -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.8.5 (2006-08-25) [i486-linux]
waiting pop...
#<Timeout::Error: execution expired>
pushing...
pushed.
poping...
1
poped.

havana$ ~/local/ruby_1_8_6/bin/ruby186 -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]
waiting pop...
#<Timeout::Error: execution expired>
pushing...
(ここでささる)

havana$ ~/local/ruby_1_8_7/bin/ruby187 -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.8.7 (2008-11-11 patchlevel 73) [i686-linux]
waiting pop...
#<Timeout::Error: execution expired>
pushing...
(ここでささる)

havana$ ~/local/ruby_1_8/bin/ruby18 -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.8.7 (2008-12-21 revision 20895) [i686-linux]
waiting pop...
#<Timeout::Error: execution expired>
pushing...
/home/kouji/work/acts/Infocast-EAR/work/timeout.rb:22:in `push': thread 0xb7dca160 tried to join itself (ThreadError)
from /home/kouji/work/acts/Infocast-EAR/work/timeout.rb:22

havana$ ruby19trunk -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.9.0 (2008-08-01 revision 18308) [i686-linux]
waiting pop...
#<Timeout::Error: execution expired>
pushing...
pushed.
poping...
1
poped.
----- 実行結果: ここまで -----
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0