Golang的Go Routine背后的架构是什么?

问题描述:

What is the architecture behind Golang's Go Routine?

I believe that Go doesn't just fork a new thread for each routine.

Golang的Go例程背后的体系结构是什么? p>

我相信Go 不只是为每个例程派生一个新线程。 p> div>

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.