In: |
thread.rb
|
Parent: | Object |
This class provides a way to communicate data between threads.
TODO: an example (code or English) would really help here. How do you set up a queue between two threads?
Creates a new queue.
# File thread.rb, line 239 def initialize @que = [] @waiting = [] @que.taint # enable tainted comunication @waiting.taint self.taint end
Returns the number of threads waiting on the queue.
# File thread.rb, line 318 def num_waiting @waiting.size end
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.
# File thread.rb, line 274 def pop(non_block=false) while (Thread.critical = true; @que.empty?) raise ThreadError, "queue empty" if non_block @waiting.push Thread.current Thread.stop end @que.shift ensure Thread.critical = false end