Created
January 26, 2014 17:15
-
-
Save quux00/8635984 to your computer and use it in GitHub Desktop.
Telephonic whispers with GOMAXPROCS set in Go.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
func whisper(left, right chan int) { | |
left <- 1 + <- right | |
} | |
func main() { | |
runtime.GOMAXPROCS(runtime.NumCPU()) | |
const n = 100000 | |
leftmost := make(chan int) | |
right := leftmost | |
left := leftmost | |
for i := 0; i < n; i++ { | |
right = make(chan int) | |
go whisper(left, right) | |
left = right | |
} | |
go func(c chan int) { c <- 1 }(right) | |
fmt.Println(<- leftmost) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment