From: "jsc (Justin Collins)" Date: 2014-01-02T15:53:31+09:00 Subject: [ruby-core:59464] [ruby-trunk - Bug #9342] [PATCH] SizedQueue#clear does not notify waiting threads in Ruby 1.9.3 Issue #9342 has been updated by jsc (Justin Collins). File 0002-Wake-waiting-threads-when-SizedQueue-clear-is-called-2.0.patch added 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. ---------------------------------------- Bug #9342: [PATCH] SizedQueue#clear does not notify waiting threads in Ruby 1.9.3 https://bugs.ruby-lang.org/issues/9342#change-44017 Author: jsc (Justin Collins) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-darwin11.4.2] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN 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. For example: 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 end t2 = Thread.new do Thread.pass sq.clear end t2.join # Empty queue t1.join # Deadlock, t1 continues to sleep -- http://bugs.ruby-lang.org/