Skip to content

Instantly share code, notes, and snippets.

@quux00
Created January 26, 2014 17:15
Show Gist options
  • Save quux00/8635984 to your computer and use it in GitHub Desktop.
Save quux00/8635984 to your computer and use it in GitHub Desktop.
Telephonic whispers with GOMAXPROCS set in Go.
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