2 ms·
It's preemptive, I just tested. Spawning an infinite loop inside a green-thread while limiting the program to 1 core does not freeze the program. This will outp
by hu3 3y ago
It's preemptive, I just tested. Spawning an infinite loop inside a green-thread while limiting the program to 1 core does not freeze the program. This will output "hello" and exit normally as expected:
package main
import (
"fmt"
"runtime"
)
func infiniteLoop() {
for {}
fmt.Println("world")
}
func main() {
runtime.GOMAXPROCS(1)
go infiniteLoop()
fmt.Println("hello")
}
For more information, see Go's source code which is exceptionally well commented:
https://go.dev/src/runtime/preempt.go https://go.dev/src/runtime/preempt.go