This class represents queues of specified size capacity. The push operation may be blocked if the capacity is full.
See Queue for an example of how a SizedQueue works.
Methods
Class Public methods
new(max)
Link
Creates a fixed-length queue with a maximum size of max
.
Instance Public methods
clear()
Link
Removes all objects from the queue.
max()
Link
Returns the maximum size of the queue.
max=(max)
Link
Sets the maximum size of the queue.
num_waiting()
Link
Returns the number of threads waiting on the queue.
pop(*args)
Link
Retrieves data from the queue and runs a waiting thread, if any.
push(obj)
Link
Pushes obj
to the queue. If there is no space left in the
queue, waits until space becomes available.
# File lib/thread.rb, line 302 def push(obj) Thread.handle_interrupt(RuntimeError => :on_blocking) do @mutex.synchronize do while true break if @que.length < @max @num_enqueue_waiting += 1 begin @enque_cond.wait @mutex ensure @num_enqueue_waiting -= 1 end end @que.push obj @cond.signal end end end