在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
package main import "fmt" func main() { workChan := make(chan int, 10000) //存储chan controlChan := make(chan int, 100) //控制chan var work int var mange int for i := 0; i < 100; i++ { go func() { defer func() {controlChan <- 1}() for j := 0; j < 100; j++ { workChan <- i } }() } for range controlChan { mange++ //当控制chal 满 则关闭控制与工作channel if mange == 100 { close(workChan) close(controlChan) } } for range workChan { work++ } fmt.Println("channel长度", work) }
|
请发表评论