Esempio n. 1
0
File: chain.go Progetto: 8l/go-learn
func link(left chan<- int, right <-chan int) {
	// Keep the links in dedicated operating system
	// threads, so that this program tests coordination
	// between pthreads and not just goroutines.
	runtime.LockOSThread()
	for {
		v := <-right
		stdio.Puts(strconv.Itoa(v))
		left <- 1 + v
	}
}
Esempio n. 2
0
File: chain.go Progetto: 8l/go-learn
func main() {
	leftmost := make(chan int)
	var left chan int
	right := leftmost
	for i := 0; i < N; i++ {
		left, right = right, make(chan int)
		go link(left, right)
	}
	for i := 0; i < R; i++ {
		right <- 0
		x := <-leftmost
		stdio.Puts(strconv.Itoa(x))
	}
}
Esempio n. 3
0
func fibber(c, out chan int64, i int64) {
	// Keep the fibbers in dedicated operating system
	// threads, so that this program tests coordination
	// between pthreads and not just goroutines.
	runtime.LockOSThread()

	if i == 0 {
		c <- i
	}
	for {
		j := <-c
		stdio.Puts(strconv.Itoa64(j))
		out <- j
		<-out
		i += j
		c <- i
	}
}
Esempio n. 4
0
func main() {
	//	stdio.Stdout.WriteString("hello, world\n");
	stdio.Puts("hello, world")
}