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) }