BoundedSemaphore class

A semaphore object that enforces an upper bound on the internal counter.

A bounded semaphore is a synchronization primitive that limits the number of concurrent accesses to a shared resource. It maintains a counter that represents the number of available resources. When a future wants to access the resource, it must acquire a permit from the semaphore. If no permits are available, the thread will be blocked until a permit becomes available.

This implementation extends the Semaphore class and adds additional logic to enforce a limit on the number of permits. If the value of the semaphore exceeds the initial value, a BoundedSemaphoreLimitException is thrown when releasing a permit.

Inheritance

Constructors

BoundedSemaphore(int value)
Construct a new BoundedSemaphore object with the initial internal counter set to value. This provided value is also the upper bound of the internal counter.

Properties

hashCode int
The hash code for this object.
no setterinherited
locked bool
Whether this semaphore cannot be acquired immediately.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
waiters int
Number of futures which are currently waiting to acquire this semaphore.
no setterinherited

Methods

acquire() Future<void>
Acquire the semaphore. If the internal counter is greater then 0, decrease it by 1 and return immediately. If the internal counter equals 0, wait asynchronously until the semaphore is available.
inherited
cancelAll() → void
Cancel all futures waiting for this semaphore to be available by throwing a SemaphoreAcquireFailureException to them.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release() → void
Release a permit from the semaphore. If the value of the semaphore is greater than the initial value, a BoundedSemaphoreLimitException is thrown.
run<T>(Future<T> func()) Future<T>
Acquire the semaphore, asynchronously run func and release the semaphore afterwards.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited