```
package main
import (
"fmt"
"time"
)
func main() {
limiter := make(chan bool, 10)
for i := 0; i < 100; i++ {
limiter <- true
go download(i, limiter)
}
}
func download(index int, limiter chan bool) {
time.Sleep(1 * time.Second)
fmt.Println("start to download :", index)
<-limiter
}
```
上面这段代码执行结果为什么最大打印值直到 89 ?
当把
```
time.Sleep(1 * time.Second)
fmt.Println("start to download :", index)
```
两行上下调换之后,变成以下的代码:
```
fmt.Println("start to download :", index)
time.Sleep(1 * time.Second)
```
就能正常打印到 99 了?
有疑问加站长微信联系(非本文作者)