- 运行下面这段代码,并解释它的输出
- 将main函数中go sing(chordC)这一行的chordC改为mute后再次运行,并解释它的输出
//chorus.go
package main
import (
"fmt"
"runtime"
)
func mute() {
for i := 0; i < 1000000000; i++ {
}
}
func sing(tones func()) {
for {
mute()
tones()
}
}
func chordC() {
fmt.Println("Do Mi So")
}
func chordG() {
fmt.Println("So Ti Re")
}
func main() {
n := runtime.NumCPU()
for i := 0; i < n; i++ {
go sing(chordC)
//go sing(mute)
}
sing(chordG)
}
网友评论