golang 是抢占式调度 如果协程不主动让出 或者 阻塞 可以一直运行
package main
import (
"fmt"
"runtime"
"runtime/debug"
"runtime/pprof"
"time"
)
func main() {
runtime.GOMAXPROCS(1)
debug.SetMaxThreads(10)
fmt.Println("start")
threadProfile := pprof.Lookup("threadcreate")
fmt.Printf(" init threads counts: %d\n", threadProfile.Count())
go func() {
for {
}
fmt.Println("end goruntine")
}()
time.Sleep(3 * time.Second)
fmt.Printf(" end threads counts: %d\n", threadProfile.Count())
fmt.Println("end")
}