Class: Higgs::CountDownLatch
- Inherits:
-
Object
- Object
- Higgs::CountDownLatch
- Defined in:
- lib/higgs/thread.rb
Constant Summary collapse
- CVS_ID =
for ident(1)
'$Id: thread.rb 841 2008-12-24 09:23:20Z toki $'
Instance Method Summary collapse
- #count_down ⇒ Object
-
#initialize(count) ⇒ CountDownLatch
constructor
A new instance of CountDownLatch.
- #wait ⇒ Object
Constructor Details
#initialize(count) ⇒ CountDownLatch
Returns a new instance of CountDownLatch.
138 139 140 141 142 |
# File 'lib/higgs/thread.rb', line 138 def initialize(count) @count = count @lock = Mutex.new @cond = ConditionVariable.new end |
Instance Method Details
#count_down ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/higgs/thread.rb', line 144 def count_down @lock.synchronize{ if (@count > 0) then @count -= 1 @cond.broadcast if (@count == 0) end } nil end |
#wait ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'lib/higgs/thread.rb', line 154 def wait @lock.synchronize{ while (@count > 0) @cond.wait(@lock) end } nil end |