[PATCH] SizedQueue#clear does not notify waiting threads in Ruby 1.9.3
In Ruby 1.9.3, when SizedQueue#clear is called, it empties the queue but does not notify waiting threads that the queue is empty. This typically leads to deadlock when the queue is full.
sq = SizedQueue.new(1)
sq << 1 # Fill queue
t1 = Thread.new do
sq << 1 # Attempt to add another item to queue, fail and go to sleep waiting
t2 = Thread.new do
t2.join # Empty queue
t1.join # Deadlock, t1 continues to sleep
#1 [ruby-core:59464] Updated by Justin Collins about 3 years ago
Looks like this is also a problem in 2.0.0, although the implementation is a little different. Attaching patch for 2.0.0 too although it's probably clear.
#4 Updated by Anonymous about 3 years ago
- % Done changed from 0 to 100
- Status changed from Open to Closed
#7 [ruby-core:60626] Updated by Tomoyuki Chikanaga about 3 years ago
- Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: DONE, 2.1: REQUIRED
1.9.3 and 2.0.0 has different implementation of Queue/SizedQueue from 2.1/trunk.
I partially backported r44595 for test, and commited a patch for ruby_2_0_0 at r44899.