4 ms·
Yes. The goroutine that increments i in a loop never has a chance to yield to the scheduler. package main import ( "fmt" "time" )
by echlebek 9y ago
Yes. The goroutine that increments i in a loop never has a chance to yield to the scheduler.
package main
import (
"fmt"
"time"
)
func main() {
go func() {
time.Sleep(100 * time.Millisecond)
fmt.Println("hi")
}()
var i int
for {
i++
}
}
$ GOMAXPROCS=1 go run test.go # never prints anything
- Matthias247 9y agoHowever that should happen only in a loop without function calls inside it. Afaik the newer Go versions will also yield in the function call preambles to the scheduler from time to time to give another goroutine in ready state the chance to run.
- echlebek 9y agoThat's right. The newer releases of Go include more points where goroutines will yield to the scheduler. I'm unsure about how that plays with inlining, though.