This class represents queues of specified size capacity. The push operation may be blocked if the capacity is full.
Creates a fixed-length queue with a maximum size of max.
# File thread.rb, line 331 def initialize(max) raise ArgumentError, "queue size must be positive" unless max > 0 @max = max @queue_wait = [] @queue_wait.taint # enable tainted comunication super() end
Sets the maximum size of the queue.
# File thread.rb, line 349 def max=(max) Thread.critical = true if max <= @max @max = max Thread.critical = false else diff = max - @max @max = max Thread.critical = false diff.times do begin t = @queue_wait.shift t.run if t rescue ThreadError retry end end end max end
# File thread.rb, line 382 def pop(*args) retval = super Thread.critical = true if @que.length < @max begin t = @queue_wait.shift t.wakeup if t rescue ThreadError retry ensure Thread.critical = false end begin t.run if t rescue ThreadError end end retval end