官术网_书友最值得收藏!

Go's runtime scheduler

The Go program, along with the runtime, is managed and executed on multiple OS threads. The runtime uses a scheduler strategy known as M:N scheduler, which will schedule M number of goroutines on N number of OS threads. As a result, whenever we need to run or switch to a different goroutine, the context switching will be fast, and this also enables us to use multiple cores of the CPU for parallel computing.

A solid understanding of Go's runtime and scheduler would be quite interesting and useful, and now would be a good time to look at them in detail.

From the Go scheduler's perspective, there are primarily three entities:

  • Goroutine (G)
  • OS thread or machine (M)
  • Context or processor (P)

Let's look at what they do. We will also be looking the partial struct definitions of these entities to provide a better idea of how scheduling is implemented and how it works.

主站蜘蛛池模板: 黄梅县| 河津市| 乌兰察布市| 大悟县| 大竹县| 奎屯市| 温州市| 泌阳县| 横峰县| 娄烦县| 江永县| 易门县| 宁夏| 江华| 桐梓县| 武清区| 丰镇市| 乌拉特后旗| 咸丰县| 连州市| 蒙阴县| 平原县| 仙居县| 名山县| 扶沟县| 郓城县| 潜江市| 锡林郭勒盟| 金乡县| 许昌县| 额尔古纳市| 民乐县| 平昌县| 万载县| 彩票| 诸暨市| 防城港市| 三门县| 平遥县| 重庆市| 萝北县|