package main
import (
"runtime"
)
func work() {
println("before")
s := make([]int, 6000000)
println("after")
s[0] = 1
}
func main() {
runtime.GOMAXPROCS(4)
//work() // This is OK. Very quick.
go work()
for {
}
}
PS: I know for{} busy wait is no good. But I'm curious to know the underlying reason.
What did you expect to see?
following print:
before
after
What did you see instead?
following printed:
before
The text was updated successfully, but these errors were encountered:
Go has a cooperative, not preemptive, scheduler. The for{} loop never reaches a preemption point, so a garbage collection cannot complete.
Dup of #10958
The for {} problem is only one special case of a non-preemptible loop. I
don't think the compiler should handle this one case but not the others.
However, handling the general problem is very hard because sometimes people
do write such tight loops to crunch data, for example, and the compiler
shouldn't insert preemption points into such deliberate tight loops.
I couldn't think of any valid use of for {} except toy examples, so I think
the status quo is fine.
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.6.1 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
PS: I know
for{}
busy wait is no good. But I'm curious to know the underlying reason.What did you expect to see?
following print:
What did you see instead?
following printed:
The text was updated successfully, but these errors were encountered: