[PATCH] SizedQueue#clear does not notify waiting threads in Ruby 1.9.3
|ruby -v:||ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin11.4.2]||Backport:||1.9.3: DONE, 2.0.0: DONE, 2.1: DONE|
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
ext/thread/thread.c (rb_szqueue_clear): notify SZQUEUE_WAITERS
on SizedQueue#clear. [Bug #9342]
test/thread/test_queue.rb: add test. the patch is from
#1 Updated by Justin Collins over 1 year 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.
#7 Updated by Tomoyuki Chikanaga over 1 year 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.