Returns the number of permits currently available.
Returns the number of permits currently available. Always nonnegative.
Reset the count of this semaphore back to zero, and return the previous count.
Reset the count of this semaphore back to zero, and return the previous count.
Throws an IllegalArgumentException
if count is below zero (due to pending
decrements).
Obtain a snapshot of the current count.
Obtain 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.
Decrement the number of available permits by n
, blocking until n
are available.
Decrement 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)
.
Increment the number of available permits by n
.
Increment the number of available permits by n
. Error if n < 0
.
This will have the effect of unblocking n
acquisitions.
Acquire n
permits now and return true
, or return false
immediately.
Acquire n
permits now and return true
, or return false
immediately. Error if n < 0
.
Decrement the number of permits by 1.
Decrement the number of permits by 1. Just calls decrementBy(1)
.
Increment the number of permits by 1.
Increment the number of permits by 1. Just calls incrementBy(1)
.
Just calls tryDecrementBy(1)
.
An asynchronous semaphore, useful as a concurrency primitive.