Skip to content

Instantly share code, notes, and snippets.

@fd
Created September 13, 2016 13:52
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 fd/7136de67a56e174d8c06cb505f7278aa to your computer and use it in GitHub Desktop.
Save fd/7136de67a56e174d8c06cb505f7278aa to your computer and use it in GitHub Desktop.
func NumActiveGoroutine() int {
num := 0
lock(&sched.lock)
lock(&allglock)
for gi := 0; gi < len(allgs); gi++ {
gp := allgs[gi]
if isSystemGoroutine(gp) {
continue
}
s := readgstatus(gp)
if s&(_Grunnable|_Grunning|_Gsyscall) > 0 {
num++
}
}
unlock(&allglock)
unlock(&sched.lock)
return num
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment