From 93c5002a7c3a157e0b3cd4192a7f26f32677562c Mon Sep 17 00:00:00 2001 From: mame Date: Fri, 16 Apr 2010 11:10:08 +0000 Subject: * lib/thread.rb (Queue#push, #pop, SizedQueue#push, #pop): remove code that kicks waiting thread twice, which caused race and deadlock. [ruby-core:25537] * test/thread/test_queue.rb: added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/thread.rb | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) (limited to 'lib/thread.rb') diff --git a/lib/thread.rb b/lib/thread.rb index 4f296bb8b3..f3831a7425 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -150,7 +150,6 @@ class Queue # Pushes +obj+ to the queue. # def push(obj) - t = nil @mutex.synchronize{ @que.push obj begin @@ -160,10 +159,6 @@ class Queue retry end } - begin - t.run if t - rescue ThreadError - end end # @@ -182,8 +177,8 @@ class Queue # thread isn't suspended, and an exception is raised. # def pop(non_block=false) - while true - @mutex.synchronize{ + @mutex.synchronize{ + while true if @que.empty? raise ThreadError, "queue empty" if non_block @waiting.push Thread.current @@ -191,8 +186,8 @@ class Queue else return @que.shift end - } - end + end + } end # @@ -295,7 +290,6 @@ class SizedQueue < Queue # until space becomes available. # def push(obj) - t = nil @mutex.synchronize{ while true break if @que.length < @max @@ -311,11 +305,6 @@ class SizedQueue < Queue retry end } - - begin - t.run if t - rescue ThreadError - end end # @@ -333,7 +322,6 @@ class SizedQueue < Queue # def pop(*args) retval = super - t = nil @mutex.synchronize { if @que.length < @max begin @@ -344,10 +332,6 @@ class SizedQueue < Queue end end } - begin - t.run if t - rescue ThreadError - end retval end -- cgit v1.2.3