summaryrefslogtreecommitdiff
path: root/lib/thread.rb
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-10 08:44:05 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-02-10 08:44:05 +0000
commit36f3603cae6536e571220721e916b8d284cf0675 (patch)
treeeb9605811483000f6980263aa163b4f627ab1c3f /lib/thread.rb
parentfd1d8cdc09ed86e4a0812120a17ff0d7b04adcaf (diff)
This commit was manufactured by cvs2svn to create tag 'v1_1b7'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_1b7@70 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/thread.rb')
-rw-r--r--lib/thread.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/thread.rb b/lib/thread.rb
index 4f294cc9a3..8f7f6cdd6a 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -13,6 +13,10 @@ unless defined? ThreadError
end
end
+if $DEBUG
+ Thread.abort_on_exception = true
+end
+
class Mutex
def initialize
@waiting = []
@@ -107,4 +111,30 @@ class Queue
def length
@que.length
end
+ alias size length
+end
+
+class SizedQueue<Queue
+ def initialize(max)
+ @max = max
+ @queue_wait = []
+ super()
+ end
+
+ def push(obj)
+ while @que.length >= @max
+ @queue_wait.push Thread.current
+ Thread.stop
+ end
+ super
+ end
+
+ def pop(*args)
+ if @que.length < @max
+ t = @queue_wait.shift
+ t.run if t
+ end
+ pop = super
+ pop
+ end
end