Semaphore
Technically a semaphore is simply an integer variable which has an execution queue associated with it.
Methods
Public Class methods
[ show source ]
# File lib/facets/more/semaphore.rb, line 29 def initialize(initvalue = 0) @counter = initvalue @waiting_list = [] end
Public Instance methods
Alias for wait
This method is also aliased as
synchronize
[ show source ]
# File lib/facets/more/semaphore.rb, line 65 def exclusive wait yield ensure signal end
Alias for wait
[ show source ]
# File lib/facets/more/semaphore.rb, line 45 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
Alias for exclusive
Alias for signal
Alias for signal
[ show source ]
# File lib/facets/more/semaphore.rb, line 34 def wait Thread.critical = true if (@counter -= 1) < 0 @waiting_list.push(Thread.current) Thread.stop end self ensure Thread.critical = false end