Issue #5258 has been updated by rklemme (Robert Klemme).


This is also present in 1.9.3 and there is an even simpler test case:

$ ruby19 -r thread -e 'q=SizedQueue.new 10;1_000_000.times {|i| p i;q.enq i}'
0
1
2
3
4
5
6
7
8
9
10
/opt/lib/ruby/1.9.1/thread.rb:301:in `sleep': deadlock detected (fatal)
        from /opt/lib/ruby/1.9.1/thread.rb:301:in `block in push'
        from <internal:prelude>:10:in `synchronize'
        from /opt/lib/ruby/1.9.1/thread.rb:297:in `push'
        from -e:1:in `block in <main>'
        from -e:1:in `times'
        from -e:1:in `<main>'

rklemme@padrklemme2 /cygdrive/c/SCMws/RKlemme/JavaProducts_oslee_ngcp_dev_R3.3_be4rb
$ ruby19 -v
ruby 1.9.3p125 (2012-02-16) [i386-cygwin]
----------------------------------------
Bug #5258: SizedQueueにBug #5195と同様のバグ
https://bugs.ruby-lang.org/issues/5258#change-25830

Author: Glass_saga (Masaki Matsushita)
Status: Assigned
Priority: Normal
Assignee: kosaki (Motohiro KOSAKI)
Category: lib
Target version: 2.0.0
ruby -v: ruby 1.9.4dev (2011-09-01 trunk 33157) [x86_64-linux]


=begin
[Bug #5195][ruby-dev:44400]と同様ですが、SizedQueue#pushでsleepしているthreadをwakeupさせると、SizedQueueの@queue_waitにそのthreadがpushされてしまいます。

 require 'thread'
 
 sq = SizedQueue.new(1)
 sq.push(0)
 
 t1 = Thread.start { sq.push(1) ; sleep }
 
 nil until t1.stop?
 t1.wakeup
 nil until t1.stop?
 
 t2 = Thread.start { sq.push(2) }
 
 nil until t1.stop? && t2.stop?
 
 p t1, t2
 sq.instance_eval{ p @queue_wait }
 
 3.times{ sq.pop }
 
 t2.join

上記のコードを実行すると、

 #<Thread:0x00000000b1a198 sleep>
 #<Thread:0x00000000b1a120 sleep>
 [#<Thread:0x00000000b1a198 sleep>, #<Thread:0x00000000b1a198 sleep>, #<Thread:0x00000000b1a120 sleep>]
 /usr/local/lib/ruby/1.9.1/thread.rb:185:in `sleep': deadlock detected (fatal)
        from /usr/local/lib/ruby/1.9.1/thread.rb:185:in `block in pop'
        from <internal:prelude>:10:in `synchronize'
        from /usr/local/lib/ruby/1.9.1/thread.rb:180:in `pop'
        from /usr/local/lib/ruby/1.9.1/thread.rb:324:in `pop'
        from sized_queue.rb:19:in `block in <main>'
        from sized_queue.rb:19:in `times'
        from sized_queue.rb:19:in `<main>'

となります。
場当たり的なものですが[Bug #5195][ruby-dev:44400]の時と同様なpatchを添付します。適用後もtest/thread/test_queue.rbをパスします。
 
=end


-- 
http://bugs.ruby-lang.org/