summaryrefslogtreecommitdiff
path: root/lib/thread.rb
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 08:28:44 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-01 08:28:44 +0000
commit1f1db611b9860291454f38459f2aed33e0877d84 (patch)
tree711d9dec916e0b854ec15d849b53bd5b69eca011 /lib/thread.rb
parentf9aef18497c42d704657566ab2f99b089dea01ae (diff)
* lib/thread.rb (ConditionVariable): use hash instead of array for
@waiters. * test/thread/test_queue.rb (test_sized_queue_and_wakeup): remove a test because @waiters no longer have a chance to duplicated. Now it's a hash. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38109 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/thread.rb')
-rw-r--r--lib/thread.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/thread.rb b/lib/thread.rb
index 47add67e89b..04847c80abc 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -52,7 +52,7 @@ class ConditionVariable
# Creates a new ConditionVariable
#
def initialize
- @waiters = []
+ @waiters = {}
@waiters_mutex = Mutex.new
end
@@ -67,7 +67,7 @@ class ConditionVariable
begin
Thread.async_interrupt_timing(StandardError => :on_blocking) do
@waiters_mutex.synchronize do
- @waiters.push(Thread.current)
+ @waiters[Thread.current] = true
end
mutex.sleep timeout
end
@@ -86,10 +86,10 @@ class ConditionVariable
def signal
Thread.async_interrupt_timing(StandardError => :on_blocking) do
begin
- t = @waiters_mutex.synchronize {@waiters.shift}
+ t, _ = @waiters_mutex.synchronize { @waiters.shift }
t.run if t
rescue ThreadError
- retry # t was alread dead?
+ retry # t was already dead?
end
end
self
@@ -100,12 +100,12 @@ class ConditionVariable
#
def broadcast
Thread.async_interrupt_timing(StandardError => :on_blocking) do
- waiters0 = nil
+ threads = nil
@waiters_mutex.synchronize do
- waiters0 = @waiters.dup
+ threads = @waiters.keys
@waiters.clear
end
- for t in waiters0
+ for t in threads
begin
t.run
rescue ThreadError