Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Side by Side Diff: misc/cgo/stdio/chain.go

Issue 180047: code review 180047: 1) Change default gofmt default settings for (Closed)
Patch Set: code review 180047: 1) Change default gofmt default settings for Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « misc/cgo/gmp/pi.go ('k') | misc/cgo/stdio/fib.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Pass numbers along a chain of threads. 5 // Pass numbers along a chain of threads.
6 6
7 package main 7 package main
8 8
9 import ( 9 import (
10 » "runtime"; 10 » "runtime"
11 » "stdio"; 11 » "stdio"
12 » "strconv"; 12 » "strconv"
13 ) 13 )
14 14
15 const N = 10 15 const N = 10
16 const R = 5 16 const R = 5
17 17
18 func link(left chan<- int, right <-chan int) { 18 func link(left chan<- int, right <-chan int) {
19 // Keep the links in dedicated operating system 19 // Keep the links in dedicated operating system
20 // threads, so that this program tests coordination 20 // threads, so that this program tests coordination
21 // between pthreads and not just goroutines. 21 // between pthreads and not just goroutines.
22 » runtime.LockOSThread(); 22 » runtime.LockOSThread()
23 for { 23 for {
24 » » v := <-right; 24 » » v := <-right
25 » » stdio.Puts(strconv.Itoa(v)); 25 » » stdio.Puts(strconv.Itoa(v))
26 » » left <- 1+v; 26 » » left <- 1+v
27 } 27 }
28 } 28 }
29 29
30 func main() { 30 func main() {
31 » leftmost := make(chan int); 31 » leftmost := make(chan int)
32 » var left chan int; 32 » var left chan int
33 » right := leftmost; 33 » right := leftmost
34 for i := 0; i < N; i++ { 34 for i := 0; i < N; i++ {
35 » » left, right = right, make(chan int); 35 » » left, right = right, make(chan int)
36 » » go link(left, right); 36 » » go link(left, right)
37 } 37 }
38 for i := 0; i < R; i++ { 38 for i := 0; i < R; i++ {
39 » » right <- 0; 39 » » right <- 0
40 » » x := <-leftmost; 40 » » x := <-leftmost
41 » » stdio.Puts(strconv.Itoa(x)); 41 » » stdio.Puts(strconv.Itoa(x))
42 } 42 }
43 } 43 }
OLDNEW
« no previous file with comments | « misc/cgo/gmp/pi.go ('k') | misc/cgo/stdio/fib.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b