Last active
September 13, 2017 06:26
-
-
Save Clarence-pan/69110342126f1559ee8fa18ed2d32f9d to your computer and use it in GitHub Desktop.
获取go-routine的ID的方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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