英文:
What is the architecture behind Golang's Go Routine?
问题
Golang的Go协程背后的架构是什么?
我相信Go不仅仅为每个协程派生一个新线程。
英文:
What is the architecture behind Golang's Go Routine?
I believe that Go doesn't just fork a new thread for each routine.
答案1
得分: 5
过去确实有过一些Go语言的实现,每个goroutine实际上都会创建一个新的线程。
在主要的Go语言实现中,一个goroutine基本上只是一个堆栈(通常很小),还有一些额外的上下文(在1.5版本中,请参见runtime/runtime2.go
中的type g
)。从一个goroutine切换到另一个goroutine意味着改变堆栈指针和指向当前运行的goroutine的线程本地变量。
英文:
There have been Go implementations in the past that did in fact create a new thread for each goroutine.
In the main Go implementation, a Go routine is basically just a stack (usually small) with some additional context (in 1.5, see type g
in runtime/runtime2.go). Changing from goroutine to another means changing the stack pointer and the thread-local variable that points to the currently running goroutine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论