Backport #915

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

Added by Kouji Takao over 5 years ago. Updated almost 3 years ago.

[ruby-dev:37545]
Status:Closed
Priority:Normal
Assignee:Shyouhei Urabe

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...
#
pushing...
pushed.
poping...
1
poped.

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

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

havana$ ~/local/ruby18/bin/ruby18 -v ~/work/acts/Infocast-EAR/work/timeout.rb
ruby 1.8.7 (2008-12-21 revision 20895) [i686-linux]
waiting pop...
#
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...
#
pushing...
pushed.
poping...
1
poped.
----- 実行結果: ここまで -----
=end

History

#1 Updated by Shyouhei Urabe about 5 years ago

  • Assignee set to Nobuyoshi Nakada
  • ruby -v set to ruby 1.8.7 (2008-11-11 patchlevel 73) [i686-linux]

=begin

=end

#2 Updated by Nobuyoshi Nakada about 5 years ago

  • Status changed from Open to Closed

=begin
Applied at changeset r22011.
=end

#3 Updated by Nobuyoshi Nakada about 5 years ago

  • Category set to ext
  • Status changed from Closed to Assigned
  • Assignee changed from Nobuyoshi Nakada to Shyouhei Urabe

=begin

=end

#4 Updated by Shyouhei Urabe about 5 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

=begin
Applied in changeset r23049.
=end

Also available in: Atom PDF