Skip to content

Instantly share code, notes, and snippets.

@Clarence-pan
Last active September 13, 2017 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Clarence-pan/69110342126f1559ee8fa18ed2d32f9d to your computer and use it in GitHub Desktop.
Save Clarence-pan/69110342126f1559ee8fa18ed2d32f9d to your computer and use it in GitHub Desktop.
获取go-routine的ID的方法
func getGoRoutineId() uint64 {
b := make([]byte, 32)
b = b[:runtime.Stack(b, false)]
b = bytes.TrimPrefix(b, []byte("goroutine "))
b = b[:bytes.IndexByte(b, ' ')]
id, err := strconv.ParseUint(string(b), 10, 64)
if err != nil {
log.Panicf("Cannot parse goroutine id from %v: %v", b, err)
}
return id
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment