首页 > 其他分享 >go程Id retrieve the current goroutine's ID

go程Id retrieve the current goroutine's ID

时间:2023-03-15 13:35:28浏览次数:45  
标签:retrieve err goroutine id go buf ID

https://github.com/petermattis/goid


func GoID() int {
var buf [64]byte
n := runtime.Stack(buf[:], false)
// 得到id字符串
idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0]
id, err := strconv.Atoi(idField)
if err != nil {
panic(fmt.Sprintf("cannot get goroutine id: %v", err))
}
return id
}

 

标签:retrieve,err,goroutine,id,go,buf,ID
From: https://www.cnblogs.com/rsapaper/p/17218181.html

相关文章