Sha256: 8c0cd66f23b6f4dc491dd28971006e9ab7acaa05336edca18ad10c99a5ea4060
Contents?: true
Size: 663 Bytes
Versions: 97
Compression:
Stored size: 663 Bytes
Contents
module Listen # Allows two threads to wait on eachother. # # @note Only two threads can be used with this Turnstile # because of the current implementation. class Turnstile attr_accessor :queue # Initialize the turnstile. # def initialize # Until Ruby offers semahpores, only queues can be used # to implement a turnstile. @queue = Queue.new end # Blocks the current thread until a signal is received. # def wait queue.pop if queue.num_waiting == 0 end # Unblocks the waiting thread if any. # def signal queue.push(:dummy) if queue.num_waiting == 1 end end end
Version data entries
97 entries across 94 versions & 8 rubygems