Import std.concurrent.locks
Semaphore
class
Public Shared Class Semaphore
Permits that threads take and give back: Acquire takes one, waiting while there's none, and Release gives them back, so no more threads than there are permits go on at once.
Examples
Const permits = Semaphore(2)
Expect(permits.TryAcquire() && permits.TryAcquire())
Expect(!permits.TryAcquire())
permits.Release()
Expect(permits.Available == 1)std/concurrent/locks.fb, line 58
-
A Semaphore with
countpermits. Panics when that's negative. -
Takes a permit, waiting while there's none.
-
Takes a permit, waiting while there's none, unless the cancellation is cancelled first, or is already, which throws a CancelledError and takes none.
-
Takes a permit unless there's none, and tells whether it did.
-
Gives back
countpermits, which needn't be ones Acquire took, waking as many threads waiting for one. Panics whencountisn't 1 or more, or when it would take the permits past what an Int holds. -
How many permits there are now, which other threads may change at any time.
Report an issue with this page or with FutureBlitz on GitHub.