GO语言管道例子

https://www.pzlzb.com/

package main
import (
    "fmt"
    "math/rand"
    "time"
)

func producer(header string, channel chan<- string) {
	for {
		channel <- fmt.Sprintf("%s, %v", header, rand.Int31())
		time.Sleep(time.Second)
	}
}

func xfz(channel <-chan string) {
	for {
		message := <- channel
		fmt.Println(message)
	}
}

func main() {
	channel := make(chan string)
	go producer("cat", channel)
	go producer("dog", channel)
	xfz(channel)
}

你可能感兴趣的:(golang,c语言)