Skip to content

Instantly share code, notes, and snippets.

@quasilyte

quasilyte/no_preempt.go

Last active Nov 8, 2018
Embed
What would you like to do?
Example of a deadlock due to the lack of a better preemption in go scheduler
package main
import (
"fmt"
"runtime"
"time"
)
// Запускать через "go run no_preempt.go".
// См. также: https://github.com/golang/go/issues/10958.
func main() {
runtime.GOMAXPROCS(1)
go func() {
for {
// Строчку ниже можно убрать из-под комментария и программа перестанет зависать намертво.
// time.Sleep(1)
}
}()
time.Sleep(100 * time.Millisecond)
fmt.Println("hello world")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment