gorutine 的9种状态

_Gidle = iota // 0

_Gidle means this goroutine was just allocated and has not yet been initialized.

_Gidle 表示这个 goroutine 刚刚被分配,还没有被初始化。


_Grunnable // 1

_Grunnable means this goroutine is on a run queue. It is not currently executing user code. The stack is not owned.

_Grunnable 表示这个 goroutine 在运行队列中。 它当前没有执行用户代码。 堆栈不属于自己。


_Grunning // 2

_Grunning means this goroutine may execute user code. The stack is owned by this goroutine. It is not on a run queue. It is assigned an M and a P (g.m and g.m.p are valid).

_Grunning 表示这个 goroutine 可以执行用户代码。 堆栈由这个 goroutine 拥有。 它不在运行队列中。 它被分配了一个 M 和一个 P(g.m 和 g.m.p 是有效的)。


_Gsyscall // 3

_Gsyscall means this goroutine is executing a system call.
It is not executing user code. The stack is owned by this goroutine. It is not on a run queue. It is assigned an M.

_Gsyscall 表示这个 goroutine 正在执行一个系统调用。它不执行用户代码。 堆栈由这个 goroutine 拥有。 它不在运行队列中。 它被分配了一个M。


_Gwaiting // 4

_Gwaiting means this goroutine is blocked in the runtime.
It is not executing user code. It is not on a run queue, but should be recorded somewhere (e.g., a channel wait queue) so it can be ready()d when necessary. The stack is not owned *except* that a channel operation may read or write parts of the stack under the appropriate channel lock. Otherwise, it is not safe to access the stack after a goroutine enters _Gwaiting (e.g., it may get moved).

_Gwaiting 表示这个 goroutine 在运行时被阻塞。 它不执行用户代码。 它不在运行队列上,但应该记录在某个地方(例如,通道等待队列),以便在必要时可以准备好()d。 它不拥有堆栈,*除非*通道操作可以在适当的通道锁下读写堆栈的一部分。 否则,在 goroutine 进入 _Gwaiting 之后访问堆栈是不安全的(例如,它可能会被移动)。


_Gmoribund_unused // 5

_Gmoribund_unused is currently unused, but hardcoded in gdb scripts.

_Gmoribund_unused 当前未使用,但在 gdb 脚本中进行了硬编码。


_Gdead // 6

_Gdead means this goroutine is currently unused. It may be just exited, on a free list, or just being initialized. It is not executing user code. It may or may not have a stack allocated. The G and its stack (if any) are owned by the M that is exiting the G or that obtained the G from the free list.

_Gdead 表示这个 goroutine 当前未被使用。 它可能刚刚退出,在空闲列表中,或者刚刚被初始化。 它不执行用户代码。 它可能有也可能没有分配堆栈。 G 及其堆栈(如果有)由退出 G 或从空闲列表中获得 G 的 M 所有。


_Genqueue_unused // 7

_Genqueue_unused is currently unused.

_Genqueue_unused 当前未使用。


_Gcopystack // 8

_Gcopystack means this goroutine's stack is being moved. It is not executing user code and is not on a run queue. The stack is owned by the goroutine that put it in _Gcopystack.

_Gcopystack 表示这个 goroutine 的堆栈正在被移动。 它没有执行用户代码并且不在运行队列中。 堆栈由将其放入 _Gcopystack 的 goroutine 拥有。


_Gpreempted // 9

_Gpreempted means this goroutine stopped itself for a suspendG preemption. It is like _Gwaiting, but nothing is yet responsible for ready()ing it. Some suspendG must CAS the status to _Gwaiting to take responsibility for ready()ing this G.

_Gpreempted 意味着这个 goroutine 停止了自己的suspendG抢占。 它就像 _Gwaiting,但还没有任何东西负责准备好它。 一些suspendG必须CAS状态到_Gwaiting来负责准备好这个G。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值