So i have a program which need to allocate a very big chunk of memory and hold it forever. As a test, i also run a goroutine which runs an infinite loop, in my main thread, i allocate the memory, however the program stuck forever in the goroutine's infinite loop even i set GOMAXPROCS to more then 1.
func main() {
runtime.GOMAXPROCS(2)
go func() {
for {
//fmt.Printf("goroutine1\n")
}
}()
fmt.Println("main thread1")
x := [1145][1145]int{}
for i := 0; i < 1144; i++ {
fmt.Println(i)
x[i][i] = i
}
fmt.Println("main thread2")
}
if i don't do anything in the infinite loop, my main thread1 will never be able to successfully allocate the memory and print "main thread2", even i set GOMAXPROCS to 2, if i print something inside the infinite loop, everythings works fine(which is expected, as the goroutine print something in the infinite loop, it invoke the system call and yield the cpu, so my main thread can allocate the memory.
i am wondering why is that?