通过 pprof 查看 go 程序的运行状况时,发现 threadcreate 总是 7 或者 8 为什么呢?
本机 runtime.NumCPU() = 4
code:
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"runtime"
)
var c = make(chan int)
func init() {
for i:=0;i<10;i++{
go func(i int) {
fmt.Println("push : ",i)
c <- i
}(i)
}
}
func main() {
// 设置使用 cpu 的最大核数
runtime.GOMAXPROCS(1)
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
for i:=0;i<5;i++{
fmt.Println("pop : ",<-c)
}
writer.Write([]byte("hello world"))
})
log.Fatal( http.ListenAndServe(":8000",nil))
}
然后访问 http://localhost:8000/debug/pprof/threadcreate?debug=1,结果为:
threadcreate profile: total 7
6 @
# 0x0
1 @ 0x103ae7e 0x103b589 0x1037d44 0x1037d45 0x1067401
# 0x103ae7d runtime.allocm+0x14d /usr/local/go/go1.14.2/src/runtime/proc.go:1390
# 0x103b588 runtime.newm+0x38 /usr/local/go/go1.14.2/src/runtime/proc.go:1704
# 0x1037d43 runtime.startTemplateThread+0x2c3 /usr/local/go/go1.14.2/src/runtime/proc.go:1768
# 0x1037d44 runtime.main+0x2c4 /usr/local/go/go1.14.2/src/runtime/proc.go:186
哪位大佬给解释下,为什么是 7 个线程。 其中 6 @ 0x0 是什么呢