在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回答

Xargin

2021-06-29

你是问 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

0
han_beta
回复
hargin
hp dir="ltr">好的,了解了,谢谢曹大

h021-06-30
共4条回复

Go高级工程师实战营

慕课网与 GoCN 社区官方联手打造,定义行业Go高级人才培养标准,4个月,快速晋升为P6+/D7级高级人才。

458 学习 · 266 问题

查看课程

相似问题

回答 4

回答 1

回答 1

回答 2