advanced-go-programming-book
advanced-go-programming-book copied to clipboard
3.8.4 getg返回interface{}后,不能这么写了吧?
有了正确的goid偏移量之后,采用前面讲过的方式获取goid:
func GetGroutineId() int64 { g := getg() p := (*int64)(unsafe.Pointer(uintptr(g) + g_goid_offset)) return *p }
是的,getg如果返回interface{}
,就可以通过reflect获取成员偏移量了
go1.14
这种获取 goroutineid 的方式,执行错误