go-eden / routine

Provides some convenient API, includes Goid(), GetG() and LocalStorage, which is a goroutine's local storage, just like ThreadLocal in other languages.
MIT License
114 stars 20 forks source link

getAllGoidByNative中是否不应该过滤gDead #7

Closed manchurio closed 2 years ago

manchurio commented 2 years ago
if runtimeReadgstatus(gp) == gDead || runtimeIsSystemGoroutine(gp, false) {
    continue
}

在系统调用/cgo/新建g的时候, g的状态也是gDead, 是否不应该在这里过滤掉gDead状态的g 因为这里的g状态虽然是dead,但等一会还是会恢复成runnable 如cgo调用

sisyphsu commented 2 years ago

此处逻辑参考了runtime.Stack的内部实现。

gDead表示协程just exitedjust being initialized,它此时没有独立的stack,不被视为有效的协程。