Class: Concurrent::Semaphore
- Inherits:
-
SemaphoreImplementation
- Object
- Concurrent::Semaphore
- Defined in:
- lib/concurrent-ruby/concurrent/atomic/semaphore.rb
Overview
A counting semaphore. Conceptually, a semaphore maintains a set of permits. Each #acquire blocks if necessary until a permit is available, and then takes it. Each #release adds a permit, potentially releasing a blocking acquirer. However, no actual permit objects are used; the Semaphore just keeps a count of the number available and acts accordingly.
Instance Method Summary collapse
-
#acquire(permits = 1) ⇒ nil
Acquires the given number of permits from this semaphore, blocking until all are available.
-
#available_permits ⇒ Integer
Returns the current number of permits available in this semaphore.
-
#drain_permits ⇒ Integer
Acquires and returns all permits that are immediately available.
-
#initialize(count) ⇒ undocumented
constructor
Create a new
Semaphore
with the initialcount
. -
#release(permits = 1) ⇒ nil
Releases the given number of permits, returning them to the semaphore.
-
#try_acquire(permits = 1, timeout = nil) ⇒ Boolean
Acquires the given number of permits from this semaphore, only if all are available at the time of invocation or within
timeout
interval.
Constructor Details
#initialize(count) ⇒ undocumented
Create a new Semaphore
with the initial count
.
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |
Instance Method Details
#acquire(permits = 1) ⇒ nil
Acquires the given number of permits from this semaphore, blocking until all are available.
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |
#available_permits ⇒ Integer
Returns the current number of permits available in this semaphore.
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |
#drain_permits ⇒ Integer
Acquires and returns all permits that are immediately available.
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |
#release(permits = 1) ⇒ nil
Releases the given number of permits, returning them to the semaphore.
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |
#try_acquire(permits = 1, timeout = nil) ⇒ Boolean
Acquires the given number of permits from this semaphore,
only if all are available at the time of invocation or within
timeout
interval
143 144 |
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 143 class Semaphore < SemaphoreImplementation end |