This question already has an answer here:
I'm currently learning golang and I've tried the following code:
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")
}
}
When I run this program, I get as output: "hello, world"
and "hello, world222"
for a few seconds. However, after a few seconds, I don't get anything anymore however the program is still running.
What's wrong? Why does the program stop displaying hello, world
and hello, world222
?
</div>