Created
December 27, 2012 05:35
-
-
Save anonymous/4385719 to your computer and use it in GitHub Desktop.
golang channel test sample 1
This file contains 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 ( | |
"runtime" | |
"fmt" | |
) | |
func test(c chan bool, b bool) { | |
x := 0.0 | |
for i := 0.0 ; i < 10000000 ; i++ { | |
x += i | |
} | |
println(x) | |
if b { | |
c <- true | |
} | |
} | |
func main() { | |
runtime.GOMAXPROCS(2) | |
c := make(chan bool) | |
for i := 0 ; i < 50 ; i ++ { | |
go test(c, i == 49) | |
} | |
fmt.Println(<-c) | |
// <-c | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment