首页 > 其他分享 >Go: Get Goroutine ID

Go: Get Goroutine ID

时间:2023-03-17 20:58:07浏览次数:25  
标签:idField err Get Goroutine id Go buf ID

 

func GetGoroutineID() int {
    var buf = make([]byte, 128)
    b := runtime.Stack(buf, false)
    idField := strings.Fields(strings.TrimPrefix(string(buf[:b]), "goroutine "))[0]
    id, err := strconv.Atoi(idField)
    if err != nil {
        panic(fmt.Sprintf("cannot get goroutine id: %v", err))
    }
    return id
}

 

标签:idField,err,Get,Goroutine,id,Go,buf,ID
From: https://www.cnblogs.com/dissipate/p/17228118.html

相关文章