Returns the number of permits currently available.
Returns the number of permits currently available. Always nonnegative.
Resets the count of this semaphore back to zero, and returns the previous count.
Resets the count of this semaphore back to zero, and returns the previous count.
Throws an IllegalArgumentException
if count is below zero (due to pending
decrements).
Obtains a snapshot of the current count.
Obtains a snapshot of the current count. May be out of date the instant
after it is retrieved. Use tryDecrement
or tryDecrementBy
if you wish to attempt a decrement and return immediately if the
current count is not high enough to satisfy the request.
Decrements the number of available permits by n
, blocking until n
are available.
Decrements the number of available permits by n
, blocking until n
are available. Error if n < 0
. The blocking is semantic; we do not
literally block a thread waiting for permits to become available.
Note that decrements are satisfied in strict FIFO order, so given
s: Semaphore[F]
with 2 permits available, a decrementBy(3)
will
always be satisfied before a later call to decrementBy(1)
.
Increments the number of available permits by n
.
Increments the number of available permits by n
. Error if n < 0
.
This will have the effect of unblocking n
acquisitions.
Like decrement but limits the amount of time spent blocking for a permit.
Like decrement but limits the amount of time spent blocking for a permit. If the permit has not been acquired after the timeout has been reached, the action completes with false. If a permit is acquired, the action completes with true.
Like decrementBy but limits the amount of time spent blocking for permits.
Like decrementBy but limits the amount of time spent blocking for permits. If all permits have not been acquired after the timeout has been reached, the action completes with the number of permits remaining to be acquired. If the requested number of permits is acquired, the action completes with 0.
Acquires n
permits now and returns true
, or returns false
immediately.
Acquires n
permits now and returns true
, or returns false
immediately. Error if n < 0
.
Decrements the number of permits by 1.
Decrements the number of permits by 1. Alias for decrementBy(1)
.
Increments the number of permits by 1.
Increments the number of permits by 1. Alias for incrementBy(1)
.
Alias for tryDecrementBy(1)
.
An asynchronous semaphore, useful as a concurrency primitive.