advanced-go-programming-book icon indicating copy to clipboard operation
advanced-go-programming-book copied to clipboard

3.8.4 getg返回interface{}后,不能这么写了吧?

Open skygragon opened this issue 4 years ago • 2 comments

有了正确的goid偏移量之后,采用前面讲过的方式获取goid:

func GetGroutineId() int64 { g := getg() p := (*int64)(unsafe.Pointer(uintptr(g) + g_goid_offset)) return *p }

skygragon avatar Feb 05 '20 04:02 skygragon

是的,getg如果返回interface{},就可以通过reflect获取成员偏移量了

chai2010 avatar Mar 19 '20 09:03 chai2010

go1.14 这种获取 goroutineid 的方式,执行错误

gamelife1314 avatar Aug 03 '20 09:08 gamelife1314