golang中获取goroutine的id号

// GetId 获取goroutine的id号
func GetId() uint64 {
	b := make([]byte, 64)
	b = b[:runtime.Stack(b, false)]
	b = bytes.TrimPrefix(b, []byte("goroutine "))
	b = b[:bytes.IndexByte(b, ' ')]
	n, _ := strconv.ParseUint(string(b), 10, 64)
	return n
}
posted @ 2023-05-20 11:47  专职  阅读(208)  评论(0编辑  收藏  举报