在runtime.mstart函数中,_g_.m.mstartfn是在哪里赋值得?
来源:1-4 Go 程序是怎么跑起来的
tan_beta
2021-06-28 18:15:46
在runtime.mstart函数中,g.m.mstartfn是在哪里赋值得?此时得m为m0,在代码中未找到m.mstartfn得赋值、
if fn := _g_.m.mstartfn; fn != nil {
fn()
}
1回答
你是问 m0 的这个 startfn 是啥对吧,
我调试了一下,本身也是没有人给它赋值的:
(dlv) p _g_.m.mstartfn
nil
(dlv) bt
0 0x000000000102df01 in runtime.mstart1
at /usr/local/go/src/runtime/proc.go:1108
1 0x000000000102de16 in runtime.mstart
at /usr/local/go/src/runtime/proc.go:1087
2 0x0000000001050ebd in runtime.rt0_go
at /usr/local/go/src/runtime/asm_amd64.s:225
(dlv) p _g_.m.mstartfn
nil
(dlv) l
> runtime.mstart1() /usr/local/go/src/runtime/proc.go:1108 (PC: 0x102df01)
Warning: debugging optimized function
1103: minit()
1104:
1105: // Install signal handlers; after minit so that minit can
1106: // prepare the thread to be able to handle the signals.
1107: if _g_.m == &m0 {
=>1108: mstartm0()
1109: }
1110:
1111: if fn := _g_.m.mstartfn; fn != nil {
1112: fn()
1113: }
(dlv)所以它就是 nil
相似问题