CountingSemaphore class
A CountingSemaphore is a synchronization primitive that maintains a counter that represents the number of available permits.
Acquire:
If the counter is 0, the caller blocks (sleeps) until the count becomes
greater than 0.
Otherwise, the counter is decremented, and the caller acquires a permit.
Release:
If any caller were blocked, one is woken up to acquire permit.
Otherwise, the counter is incremented.
Constructors
- CountingSemaphore(int initialCount, int maxCount)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
acquire(
) → Future< void> - Acquires a permit from this semaphore.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
release(
) → Future< void> - Releases a permit.
-
toString(
) → String -
A string representation of this object.
inherited
-
tryAcquire(
Duration timeout) → Future< bool> -
Tries to acquire a permit from this semaphore and waits until the
specified timeout expires.
If the semaphore is locked and timeout is zero (or not specified),falseis returned.
If the timeout expires before the semaphore is unlocked, then returnsfalse.
If permit was acquired, returnstrue.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited