Technically a semaphore is simply an integer variable which has an execution queue associated with it.
# File lib/more/facets/semaphore.rb, line 67 67: def exclusive 68: wait 69: yield 70: ensure 71: signal 72: end
# File lib/more/facets/semaphore.rb, line 47 47: def signal 48: Thread.critical = true 49: begin 50: if (@counter += 1) <= 0 51: t = @waiting_list.shift 52: t.wakeup if t 53: end 54: rescue ThreadError 55: retry 56: end 57: self 58: ensure 59: Thread.critical = false 60: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.