# # thread.rb - thread support classes # $Date$ # by Yukihiro Matsumoto # unless defined? Thread fail "Thread not available for this ruby interpreter" end unless defined? ThreadError class ThreadError= max @max = max Thread.critical = false else diff = max - @max @max = max Thread.critical = false diff.times do t = @queue_wait.shift t.run if t end end max end def push(obj) Thread.critical = true while @que.length >= @max @queue_wait.push Thread.current Thread.stop Thread.critical = true end super end def pop(*args) Thread.critical = true if @que.length < @max t = @queue_wait.shift t.run if t end super end def num_waiting @waiting.size + @queue_wait.size end end