go语言channel测试

go语言channel测试,请注意空格

package main
import "fmt"

const num_go_routine = 10000

func channeltest(left,right chan int){
	left<-1+<-right;
}

func main(){
	leftmost := make(chan int);

	var left,right chan int = nil,leftmost;
	for i:=0; i<num_go_routine; i++ {
		left, right = right, make(chan int);
		go channeltest(left,right);
	}

	right<-0;
	x := <-leftmost;
	fmt.Println(x);
}

注:本示例程序来自于《代码的未来》,松本行弘

Comments are closed.