Go-goroutine
goroutine
package main
import (
"fmt"
"strconv"
"time"
)
func test() {
for i := 1; i <= 10; i++ {
fmt.Println("test () hello world" + strconv.Itoa((i)))
time.Sleep(time.Second)
}
}
func main() {
go test()
for i := 1; i <= 10; i++ {
fmt.Println("main () hello world" + strconv.Itoa((i)))
time.Sleep(time.Second)
}
}
设置Golang运行的cpu数
package main
import (
"fmt"
"runtime"
)
func main() {
cpuNum := runtime.NumCPU()
fmt.Println("cpuNum=", cpuNum)
runtime.GOMAXPROCS(cpuNum - 1)
fmt.Println("OK")
}
转载请注明出处,欢迎讨论和交流!