diff options
Diffstat (limited to 'misc/cgo/stdio')
-rw-r--r-- | misc/cgo/stdio/chain.go | 30 | ||||
-rw-r--r-- | misc/cgo/stdio/fib.go | 34 | ||||
-rw-r--r-- | misc/cgo/stdio/file.go | 8 |
3 files changed, 36 insertions, 36 deletions
diff --git a/misc/cgo/stdio/chain.go b/misc/cgo/stdio/chain.go index 18c598d4d..dd5e01542 100644 --- a/misc/cgo/stdio/chain.go +++ b/misc/cgo/stdio/chain.go @@ -7,9 +7,9 @@ package main import ( - "runtime"; - "stdio"; - "strconv"; + "runtime" + "stdio" + "strconv" ) const N = 10 @@ -19,25 +19,25 @@ 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(); + runtime.LockOSThread() for { - v := <-right; - stdio.Puts(strconv.Itoa(v)); - left <- 1+v; + v := <-right + stdio.Puts(strconv.Itoa(v)) + left <- 1+v } } func main() { - leftmost := make(chan int); - var left chan int; - right := leftmost; + 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); + 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)); + right <- 0 + x := <-leftmost + stdio.Puts(strconv.Itoa(x)) } } diff --git a/misc/cgo/stdio/fib.go b/misc/cgo/stdio/fib.go index 1e2336d5b..63ae04988 100644 --- a/misc/cgo/stdio/fib.go +++ b/misc/cgo/stdio/fib.go @@ -10,38 +10,38 @@ package main import ( - "runtime"; - "stdio"; - "strconv"; + "runtime" + "stdio" + "strconv" ) 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(); + runtime.LockOSThread() if i == 0 { c <- i } for { - j := <-c; - stdio.Puts(strconv.Itoa64(j)); - out <- j; - <-out; - i += j; - c <- i; + j := <-c + stdio.Puts(strconv.Itoa64(j)) + out <- j + <-out + i += j + c <- i } } func main() { - c := make(chan int64); - out := make(chan int64); - go fibber(c, out, 0); - go fibber(c, out, 1); - <-out; + c := make(chan int64) + out := make(chan int64) + go fibber(c, out, 0) + go fibber(c, out, 1) + <-out for i := 0; i < 90; i++ { - out <- 1; - <-out; + out <- 1 + <-out } } diff --git a/misc/cgo/stdio/file.go b/misc/cgo/stdio/file.go index c8493a0e3..7d1f22280 100644 --- a/misc/cgo/stdio/file.go +++ b/misc/cgo/stdio/file.go @@ -35,8 +35,8 @@ func (f *File) WriteString(s string) { */ func Puts(s string) { - p := C.CString(s); - C.puts(p); - C.free(unsafe.Pointer(p)); - C.fflushstdout(); + p := C.CString(s) + C.puts(p) + C.free(unsafe.Pointer(p)) + C.fflushstdout() } |