Class: Concurrent::Semaphore
Relationships & Source Files | |
Inherits: |
Concurrent::SemaphoreImplementation
|
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. Alternatively, permits may be acquired within a block, and automatically released after the block finishes executing.
Class Method Summary
-
.new(count)
constructor
Create a new
Semaphore
with the initialcount
.
Instance Method Summary
-
#acquire(permits = 1) ⇒ nil, BasicObject
Acquires the given number of permits from this semaphore,.
-
#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.
-
#release(permits = 1) ⇒ nil
Releases the given number of permits, returning them to the semaphore.
-
#try_acquire(permits = 1, timeout = nil) ⇒ true, ...
Acquires the given number of permits from this semaphore,.
Constructor Details
.new(count)
Create a new Semaphore
with the initial count
.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end
Instance Method Details
#acquire(permits = 1) ⇒ nil
, BasicObject
Acquires the given number of permits from this semaphore,
blocking until all are available. If a block is given,
yields to it and releases the permits afterwards.
is given, its return value is returned.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end
#available_permits ⇒ Integer
Returns the current number of permits available in this semaphore.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end
#drain_permits ⇒ Integer
Acquires and returns all permits that are immediately available.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end
#release(permits = 1) ⇒ nil
Releases the given number of permits, returning them to the semaphore.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end
#try_acquire(permits = 1, timeout = nil) ⇒ true
, ...
Acquires the given number of permits from this semaphore,
only if all are available at the time of invocation or within
{timeout} interval. If a block is given, yields to it if the permits
were successfully acquired, and releases them afterward, returning the
block's return value.
# File 'lib/concurrent-ruby/concurrent/atomic/semaphore.rb', line 161
class Semaphore < SemaphoreImplementation end