I'm learning golang. I have a goroutine to print variable i
and after it I write a deadloop. But when var i
up to 491519(or some other value)
, there is no output on the terminal. It looks like the goroutine which print var i
is no longer be scheduled, the CPU execute the deadloop all the way after output 491519
. Who can tell me the reason?
thanks.
My code:
package main
import (
"fmt"
"runtime"
)
func main() {
go func() {
i := 1
for {
fmt.Println(i)
i = i + 1
}
}()
runtime.GOMAXPROCS(4)
for {
}
}
I'd like to add that:
When I add fmt.Println("ABC")
in the last deadloop, the alternation of ABC
or i
output on the terminal forever.
my go version: go version go1.9.1 darwin/amd64