设定信号数量,取出、归还,以限制某功能同时允许进入的数量 go get golang.org/x/sync/semaphore import ( "golang.org/x/sync/semaphore" ) var sem = semaphore.NewWeighted(10) func f
package main import ( "fmt" "time" ) func main() { fmt.Println(time.Now().UnixMilli()) defer fmt.Println(time.Now()) // 或 defer test1(time.N
Cond 使协程进入阻塞状态,等待其它线程完成某件事后,使协程继续工作 var mu sync.Mutex cond := sync.NewCond(&mu) //传入的是Locker接口,也就是不限定必须是Mutex,实现了Lock和Unlock就可以 sharedResource := 0