本文介绍了Go如何决定什么时候在goroutine之间切换上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇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?
推荐答案
一个抢先调度器,但一个是。所以不,Go将不会在仅限CPU的计算期间切换上下文,仅在I / O期间(从内存读取也被视为I / O,如果它不在寄存器中)。您可以在中阅读一些讨论。
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.
这篇关于Go如何决定什么时候在goroutine之间切换上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!