Semaphore class final

Simple counting semaphore for limiting concurrency across independently scheduled async work (port of omp's Semaphore).

A CancelToken passed to acquire removes the waiter from the queue on cancellation so an abandoned waiter can never be admitted later and permanently shrink effective concurrency (omp issue #3464 feedback).

Constructors

Semaphore(int max)
Creates a semaphore admitting at most max concurrent holders; max <= 0 means unbounded.

Properties

current → int
The number of slots currently held.
no setter
hashCode → int
The hash code for this object.
no setterinherited
max → int
The configured ceiling (a huge sentinel when unbounded).
no setter
queued → int
Waiters still queued for a slot.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

acquire([CancelToken? cancelToken]) → Future<void>
Resolves when a slot is available.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release() → void
Releases one slot, admitting the next queued waiter when under the (possibly just-lowered) ceiling.
resize(int max) → void
Adjusts the maximum concurrency in place (omp's resize). Raising the ceiling immediately admits queued waiters that now fit; lowering it lets in-flight holders drain naturally.
toString() → String
A string representation of this object.
inherited

Operators

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