summaryrefslogtreecommitdiff
path: root/lib/thread.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread.rb')
-rw-r--r--lib/thread.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/thread.rb b/lib/thread.rb
index d4b6ad6ec1..0537c78650 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -74,7 +74,10 @@ class Mutex
retry
end
Thread.critical = false
- t.run if t
+ begin
+ t.run if t
+ rescue ThreadError
+ end
self
end
@@ -160,7 +163,10 @@ class Queue
ensure
Thread.critical = false
end
- t.run if t
+ begin
+ t.run if t
+ rescue ThreadError
+ end
end
def enq(obj)
push(obj)
@@ -170,7 +176,7 @@ class Queue
Thread.critical = true
begin
loop do
- if @que.length == 0
+ if @que.empty?
if non_block
raise ThreadError, "queue empty"
end
@@ -184,13 +190,11 @@ class Queue
Thread.critical = false
end
end
- def shift(non_block=false)
- pop(non_block=false)
- end
- alias deq shift
+ alias shift pop
+ alias deq pop
def empty?
- @que.length == 0
+ @que.empty?
end
def clear
@@ -223,11 +227,11 @@ class SizedQueue<Queue
def max=(max)
Thread.critical = true
- if max >= @max
+ if max <= @max
@max = max
Thread.critical = false
else
- diff = max - @max
+ diff = @max - max
@max = max
Thread.critical = false
diff.times do
@@ -253,6 +257,7 @@ class SizedQueue<Queue
end
def pop(*args)
+ retval = super
Thread.critical = true
if @que.length < @max
begin
@@ -263,9 +268,12 @@ class SizedQueue<Queue
ensure
Thread.critical = false
end
- t.run if t
+ begin
+ t.run if t
+ rescue ThreadError
+ end
end
- super
+ retval
end
def num_waiting