golang 线程池
发布时间:2020-12-16 18:16:57 所属栏目:大数据 来源:网络整理
导读:package mainimport "fmt"func worker(id int,jobs chan int,results chan int) { for j := range jobs { fmt.Println("worker",id,"procesing job",j) results - j * 2 }}func main() { job := make(chan int,100) result := make(chan int,200) for w := 1
package main
import "fmt"
func worker(id int,jobs chan int,results chan int) {
for j := range jobs {
fmt.Println("worker",id,"procesing job",j)
results <- j * 2
}
}
func main() {
job := make(chan int,100)
result := make(chan int,200)
for w := 1; w <=3; w++ {
go worker(w,job,result)
}
for j := 1; j <= 9; j++ {
job <- j
}
for a := 1; a <= 9; a++ {
fmt.Println(<-result)
}
} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
