Golang的Go协程背后的架构是什么?

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

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.

huangapple
  • 本文由 发表于 2015年9月24日 10:25:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/32752356.html
匿名

发表评论

匿名网友

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

确定