我目前正在学习 golang,并且尝试了以下代码:
package main
import (
"fmt"
)
func main() {
go routine()
go routine2()
fmt.Println("I am not interrupted by Go routine :)")
for {
}
}
func routine() {
for {
fmt.Println("hello, world!")
}
}
func routine2() {
for {
fmt.Println("hello, world222")
}
}
当我运行这个程序时,我得到了输出:"hello, world"
和"hello, world222"
几秒钟。然而,几秒钟后,我什么也没有得到,但程序仍在运行。
怎么了?为什么程序停止显示hello, world
和hello, world222
?