如何在golang MPG模型中获得g

wan*_*zhe 3 runtime go

我正在阅读 golang(go1.6.2 linux/amd64) 的一些运行时代码,有人可以帮助我理解 runtime/stubs.go 文件中 getg() 函数的底层机制吗?

// getg returns the pointer to the current g.
// The compiler rewrites calls to this function into instructions
// that fetch the g directly (from TLS or from the dedicated register).
func getg() *g
Run Code Online (Sandbox Code Playgroud)

getg() 函数在这里如何操作?这个函数的主体是什么?

Jim*_*imB 5

请参阅没有函数体的函数签名,以及函数声明的规范。

runtime.getg代码由编译器直接发出的情况下。