Class Queue
In: ext/fastthread/fastthread.c
Parent: Object

This class provides a way to synchronize communication between threads.

Example:

  require 'thread'

  queue = Queue.new

  producer = Thread.new do
    5.times do |i|
      sleep rand(i) # simulate expense
      queue << i
      puts "#{i} produced"
    end
  end

  consumer = Thread.new do
    5.times do |i|
      value = queue.pop
      sleep rand(i/2) # simulate expense
      puts "consumed #{value}"
    end
  end

  consumer.join

Methods

clear   empty?   length   num_waiting   pop   push  

Public Instance methods

Removes all objects from the queue.

Returns true if the queue is empty.

Returns the length of the queue.

Returns the number of threads waiting on the queue.

call_seq: pop(non_block=false)

Retrieves data from the queue. If the queue is empty, the calling thread is suspended until data is pushed onto the queue. If non_block is true, the thread isn‘t suspended, and an exception is raised.

Pushes obj to the queue.

[Validate]