Parent

Semaphore

Semaphore

Technically a semaphore is simply an integer variable which has an execution queue associated with it.

Public Class Methods

new(initvalue = 0) click to toggle source
    # File lib/more/facets/semaphore.rb, line 31
31:   def initialize(initvalue = 0)
32:     @counter = initvalue
33:     @waiting_list = []
34:   end

Public Instance Methods

down() click to toggle source
Alias for: wait
exclusive() click to toggle source
    # File lib/more/facets/semaphore.rb, line 67
67:   def exclusive
68:     wait
69:     yield
70:   ensure
71:     signal
72:   end
Also aliased as: synchronize
p() click to toggle source
Alias for: wait
signal() click to toggle source
    # 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
Also aliased as: up, v
synchronize() click to toggle source
Alias for: exclusive
up() click to toggle source
Alias for: signal
v() click to toggle source
Alias for: signal
wait() click to toggle source
    # File lib/more/facets/semaphore.rb, line 36
36:   def wait
37:     Thread.critical = true
38:     if (@counter -= 1) < 0
39:       @waiting_list.push(Thread.current)
40:       Thread.stop
41:     end
42:     self
43:   ensure
44:     Thread.critical = false
45:   end
Also aliased as: down, p

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.