Files

Class/Module Index [+]

Quicksearch

Concurrent::PureCountDownLatch

@!macro [attach] count_down_latch

A synchronization object that allows one thread to wait on multiple other threads.
The thread that will wait creates a `CountDownLatch` and sets the initial value
(normally equal to the number of other threads). The initiating thread passes the
latch to the other threads then waits for the other threads by calling the `#wait`
method. Each of the other threads calls `#count_down` when done with its work.
When the latch counter reaches zero the waiting thread is unblocked and continues
with its work. A `CountDownLatch` can be used only once. Its value cannot be reset.

@!visibility private @!macro internal_implementation_note

Public Class Methods

new(count = 1) click to toggle source

@!macro [attach] count_down_latch_method_initialize

Create a new `CountDownLatch` with the initial `count`.

@param [Fixnum] count the initial count

@raise [ArgumentError] if `count` is not an integer or is less than zero
# File lib/concurrent/atomic/count_down_latch.rb, line 26
def initialize(count = 1)
  unless count.is_a?(Fixnum) && count >= 0
    raise ArgumentError.new('count must be in integer greater than or equal zero')
  end
  super()
  synchronize { ns_initialize count }
end

Public Instance Methods

count() click to toggle source

@!macro [attach] count_down_latch_method_count

The current value of the counter.

@return [Fixnum] the current value of the counter
# File lib/concurrent/atomic/count_down_latch.rb, line 61
def count
  synchronize { @count }
end
count_down() click to toggle source

@!macro [attach] count_down_latch_method_count_down

Signal the latch to decrement the counter. Will signal all blocked threads when
the `count` reaches zero.
# File lib/concurrent/atomic/count_down_latch.rb, line 49
def count_down
  synchronize do
    @count -= 1 if @count > 0
    ns_broadcast if @count == 0
  end
end
wait(timeout = nil) click to toggle source

@!macro [attach] count_down_latch_method_wait

Block on the latch until the counter reaches zero or until `timeout` is reached.

@param [Fixnum] timeout the number of seconds to wait for the counter or `nil`
  to block indefinitely
@return [Boolean] `true` if the `count` reaches zero else false on `timeout`
# File lib/concurrent/atomic/count_down_latch.rb, line 41
def wait(timeout = nil)
  synchronize { ns_wait_until(timeout) { @count == 0 } }
end

Protected Instance Methods

ns_initialize(count) click to toggle source
# File lib/concurrent/atomic/count_down_latch.rb, line 67
def ns_initialize(count)
  @count = count
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.