package main
import (
"fmt"
"time"
)
func Producer(out chan<- int) {
for i := 0; i < 100; i++ {
out <- i
}
}
func Consumer(in <-chan int) {
for v := range in {
fmt.Println(v)
}
}
func main() {
ch := make(chan int, 4)
go Producer(ch)
go Consumer(ch)
//阻塞
time.Sleep(time.Second * 1)
}
多线程--生产者消费者模型
猜你喜欢
转载自blog.csdn.net/qq_36607792/article/details/81544211
今日推荐
周排行