Technically a semaphore is simply an integer variable which has an execution queue associated with it.
# File lib/more/facets/semaphore.rb, line 31 def initialize(initvalue = 0) @counter = initvalue @waiting_list = [] end
# File lib/more/facets/semaphore.rb, line 67 def exclusive wait yield ensure signal end
# File lib/more/facets/semaphore.rb, line 47 def signal Thread.critical = true begin if (@counter += 1) <= 0 t = @waiting_list.shift t.wakeup if t end rescue ThreadError retry end self ensure Thread.critical = false end