channel阻塞
channel阻塞后果
解决办法
生产者消费者代码实战
_package _main
import (
“fmt”
“time”)
var (
infos = make(_chan _int,10)
)
// 生产者
_func _producer(index int){
infos <- index
fmt.Printf(“Producer : %d, Sent : %d\n”,index,index)
}
// 消费者
_func _consumer(index int){
fmt.Printf(“Consumer : %d, Receive : %d\n”,index,<-infos)
}
func _main(){
// 十个生产者
_for _index := 0; index < 10; index++ {
_go _producer(index)
}
// 十个消费者 _
_for _index := 0; index < 10; index++ {
_go _consumer(index)
}
time.Sleep(20 * time.Second)
}





