summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-30 00:59:52 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-30 00:59:52 +0000
commit2dd9d721ed6820a584654c82f4ae1d6331f78a9e (patch)
tree8727ff66e424d7ae7621a06c7fb7e9c60331fbe9 /lib
parent3ffa44622db2386727a8e11bb3aeb0385621f9fa (diff)
* lib/thread.rb (Queue#pop): fix a race against Thread.wakeup.
Patch by Masaki Matsushita <glass.saga at gmail dot com> [Bug #5195] [ruby-dev:44400] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/thread.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/thread.rb b/lib/thread.rb
index 58c4f6b9e69..09f2d58ecc4 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -185,7 +185,9 @@ class Queue
while true
if @que.empty?
raise ThreadError, "queue empty" if non_block
- @waiting.push Thread.current
+ # @waiting.include? check is necessary for avoiding a race against
+ # Thread.wakeup [Bug 5195]
+ @waiting.push Thread.current unless @waiting.include?(Thread.current)
@mutex.sleep
else
return @que.shift