time.Sleep() 是否屈服于其他 goroutines?
Does time.Sleep() yield to other goroutines?
在 Go 中,对 time.Sleep() 的调用会产生给其他 goroutines 吗?我有一种感觉,但在其他答案中(例如:Understanding goroutines)time.Sleep 未明确列为调度点。
是的。参见 Pre-emption in the scheduler。
In prior releases, a goroutine that was looping forever could starve out other goroutines on the same thread, a serious problem when GOMAXPROCS provided only one user thread. In Go 1.2, this is partially addressed: The scheduler is invoked occasionally upon entry to a function. This means that any loop that includes a (non-inlined) function call can be pre-empted, allowing other goroutines to run on the same thread.
以下设计文档也是了解有关调度程序的更多信息的好读物:
在 Go 中,对 time.Sleep() 的调用会产生给其他 goroutines 吗?我有一种感觉,但在其他答案中(例如:Understanding goroutines)time.Sleep 未明确列为调度点。
是的。参见 Pre-emption in the scheduler。
In prior releases, a goroutine that was looping forever could starve out other goroutines on the same thread, a serious problem when GOMAXPROCS provided only one user thread. In Go 1.2, this is partially addressed: The scheduler is invoked occasionally upon entry to a function. This means that any loop that includes a (non-inlined) function call can be pre-empted, allowing other goroutines to run on the same thread.
以下设计文档也是了解有关调度程序的更多信息的好读物: