You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to get the ids of all the currently surviving goroutines, or to judge the survival status of the current goroutines based on the id of current goroutine?
#42629
I created a map to store some information the current goroutine, the key is the id of the current goroutine, and I plan to delete the key-value after the goroutine dies. How can I get the status of the goroutine?
I get the goroutine Id by
func GetGoroutineId() int64 {
var (
buf [64]byte
n = runtime.Stack(buf[:], false)
stk = strings.TrimPrefix(string(buf[:n]), "goroutine ")
)
idField := strings.Fields(stk)[0]
id, err := strconv.Atoi(idField)
if err != nil {
log.Errorf("can not get goroutine id: %v", err)
}
return int64(id)
}
What version of Go are you using (go version)?
$ go version 1.15
The text was updated successfully, but these errors were encountered:
I created a map to store some information the current goroutine, the key is the id of the current goroutine, and I plan to delete the key-value after the goroutine dies. How can I get the status of the goroutine?
I get the goroutine Id by
What version of Go are you using (
go version
)?The text was updated successfully, but these errors were encountered: