Hi. I’ve been wrestling with something very strange in one of my programs recently. Here is a minimal test case that reproduces it:
package main
import (
"fmt"
)
func main() {
c := make(chan int)
go func() {
i := 0
for {
c <- i
i++
}
}()
go func() {
for {
fmt.Println(<-c)
}
}()
for {
//Uncommenting this makes the program run infinitely as expected:
//fmt.Print("")
}
}
When I run this program on my machine with the fmt.Print commented out, it gets stuck on the channel send/receive after printing numbers up to around ~260,000. When I uncomment the fmt.Print, it runs forever. Is this somehow expected behavior? I feel like I’m missing something here.
If it’s relevant, I’m running 64-bit Ubuntu 15.10 with version 1.5.1 of go.