This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'monitor' | |
class Semaphore | |
def initialize(maxval = nil) | |
maxval = maxval.to_i unless maxval.nil? | |
raise ArgumentError.new("Semaphores must use a positive maximum value or have no maximum!") if maxval and maxval <= 0 | |
@max = maxval || -1 | |
@count = 0 | |
@mon = Monitor.new | |
@dwait = @mon.new_cond | |
@uwait = @mon.new_cond |