package main
import("fmt")funcputNum(num int, intchan chanint){for i :=2; i < num; i++{
intchan <- i
}close(intchan)}funcgetPrime(intchan, primechan chanint, exitchan chanbool){var flag boolfor{
num, ok :=<-intchan
flag =trueif!ok {break}for i :=2; i < num; i++{if num%i ==0{
flag =falsebreak//primechan <- num}}if flag {
primechan <- num
}}
exitchan <-true//close(primechan)
fmt.Println("管道中无数据")}funcmain(){
num :=5000000
intchan :=make(chanint, num)
primechan :=make(chanint,20)
exitchan :=make(chanbool,12)putNum(num, intchan)for i :=0; i <12; i++{gogetPrime(intchan, primechan, exitchan)}gofunc(){for i :=0; i <4; i++{<-exitchan
}close(primechan)}()for{
res, ok :=<-primechan
if!ok {break}
fmt.Println(res)}}