Parent

Methods

Listen::Turnstile

Allows two threads to wait on eachother.

@note Only two threads can be used with this Turnstile

because of the current implementation.

Attributes

queue[RW]

Public Class Methods

new() click to toggle source

Initialize the turnstile.

# File lib/listen/turnstile.rb, line 12
def initialize
  # Until Ruby offers semahpores, only queues can be used
  # to implement a turnstile.
  @queue = Queue.new
end

Public Instance Methods

signal() click to toggle source

Unblocks the waiting thread if any.

# File lib/listen/turnstile.rb, line 26
def signal
  queue.push(:dummy) if queue.num_waiting == 1
end
wait() click to toggle source

Blocks the current thread until a signal is received.

# File lib/listen/turnstile.rb, line 20
def wait
  queue.pop if queue.num_waiting == 0
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.