package semaphore
Import Path
golang.org/x/sync/semaphore (on go.dev)
Dependency Relation
imports 3 packages, and imported by one package
Involved Source Files
Package semaphore provides a weighted semaphore implementation.
Package-Level Type Names (total 2, in which 1 are exported)
Weighted provides a way to bound concurrent access to a resource.
The callers can request access with a given weight.
cur int64
mu sync.Mutex
size int64
waiters list.List
Acquire acquires the semaphore with a weight of n, blocking until resources
are available or ctx is done. On success, returns nil. On failure, returns
ctx.Err() and leaves the semaphore unchanged.
If ctx is already done, Acquire may still succeed without blocking.
Release releases the semaphore with a weight of n.
TryAcquire acquires the semaphore with a weight of n without blocking.
On success, returns true. On failure, returns false and leaves the semaphore unchanged.
(*T) notifyWaiters()
func NewWeighted(n int64) *Weighted
Package-Level Functions (only one, which is exported)
NewWeighted creates a new weighted semaphore with the given
maximum combined weight for concurrent access.
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |