golang多进程测试代码

package main

import (
"fmt"
"runtime"
) func test(c chan bool, n int) { x := 0
for i := 0; i < 1000000000; i++ {
x += i
} println(n, x) if n == 9 {
c <- true
}
} func main() {
runtime.GOMAXPROCS(1) //设置cpu的核的数量,从而实现高并发
c := make(chan bool) for i := 0; i < 10; i++ {
go test(c, i)
} <-c fmt.Println("main ok") }
上一篇:Codeforces 113A-Grammar Lessons(实现)


下一篇:Windows Live Writer介绍及相关问题解决