Class: Griffin::CountingSemaphore
- Inherits:
-
Object
- Object
- Griffin::CountingSemaphore
- Defined in:
- lib/griffin/counting_semaphore.rb
Instance Method Summary collapse
-
#initialize(size) ⇒ CountingSemaphore
constructor
A new instance of CountingSemaphore.
- #signal ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(size) ⇒ CountingSemaphore
5 6 7 8 9 |
# File 'lib/griffin/counting_semaphore.rb', line 5 def initialize(size) @size = size @queue = Queue.new @size.times { @queue.push(0) } end |
Instance Method Details
#signal ⇒ Object
15 16 17 |
# File 'lib/griffin/counting_semaphore.rb', line 15 def signal @queue.push(0) end |
#wait ⇒ Object
11 12 13 |
# File 'lib/griffin/counting_semaphore.rb', line 11 def wait @queue.pop end |