Go语言是如何决定何时在goroutine之间进行上下文切换的呢?

huangapple go评论94阅读模式
英文:

How does Go decide when to context switch between goroutines?

问题

Go语言是如何调度goroutine的呢?它是仅在通道请求和I/O时切换,还是有一个周期性的协程切换循环呢?

英文:

I am curious as to how the Go language schedules goroutines. Does it switch only during channel requests and I/O or does it have a periodic coroutine switching loop?

答案1

得分: 8

Go目前还没有预先调度程序,但计划在1.2版本中添加一个。因此,Go在仅进行CPU计算时不会切换上下文,只会在进行I/O操作时切换上下文(如果内存读取不在寄存器中,则也被视为I/O操作)。你可以在Issue 543 - preemptive scheduling中阅读一些相关讨论。

英文:

Go does not have a preemptive scheduler yet, but one is planned for 1.2. So no, Go will not switch context during CPU-only calculations, only during I/O (reading from memory is also considered I/O if it isn't in a register already). You can read some discussion about it in Issue 543 - preemptive scheduling.

huangapple
  • 本文由 发表于 2013年8月31日 15:12:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/18545595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定