Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Semaphore ¶
type Semaphore struct {
// contains filtered or unexported fields
}
Semaphore 是一个信号量,用于限制同时访问共享资源的 goroutine 数量。 它的实现基于带缓冲的通道。
func NewSemaphore ¶
NewSemaphore 创建一个新的 Semaphore。 参数 capacity 指定信号量的容量,即允许同时访问的最大 goroutine 数量。
func (*Semaphore) Acquire ¶
func (sem *Semaphore) Acquire()
Acquire 获取信号量。 如果信号量已满,调用此方法的 goroutine 会阻塞直到有可用的容量。
func (*Semaphore) Release ¶
func (sem *Semaphore) Release()
Release 释放信号量。 调用此方法会释放一个信号量容量,允许其他 goroutine 获取。
func (*Semaphore) TryAcquire ¶
type SemaphoreByCond ¶
type SemaphoreByCond struct {
// contains filtered or unexported fields
}
func NewSemaphoreByCond ¶
func NewSemaphoreByCond(capacity int) *SemaphoreByCond
func (*SemaphoreByCond) Acquire ¶
func (sm *SemaphoreByCond) Acquire()
func (*SemaphoreByCond) Release ¶
func (sm *SemaphoreByCond) Release()
func (*SemaphoreByCond) TryAcquire ¶
func (sm *SemaphoreByCond) TryAcquire() bool
Click to show internal directories.
Click to hide internal directories.