1
0
mirror of https://github.com/golang/go synced 2024-10-04 01:31:25 -06:00
go/misc/cgo/stdio/chain.go
Robert Griesemer 5a1d3323fe 1) Change default gofmt default settings for
parsing and printing to new syntax.

                  Use -oldparser to parse the old syntax,
                  use -oldprinter to print the old syntax.

               2) Change default gofmt formatting settings
                  to use tabs for indentation only and to use
                  spaces for alignment. This will make the code
                  alignment insensitive to an editor's tabwidth.

                  Use -spaces=false to use tabs for alignment.

               3) Manually changed src/exp/parser/parser_test.go
                  so that it doesn't try to parse the parser's
                  source files using the old syntax (they have
                  new syntax now).

               4) gofmt -w src misc test/bench

	       1st set of files.

R=rsc
CC=agl, golang-dev, iant, ken2, r
https://golang.org/cl/180047
2009-12-15 15:33:31 -08:00

44 lines
840 B
Go

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Pass numbers along a chain of threads.
package main
import (
"runtime"
"stdio"
"strconv"
)
const N = 10
const R = 5
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
}
}
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))
}
}