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

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.

主站蜘蛛池模板: 从化市| 恩平市| 通江县| 新巴尔虎左旗| 都匀市| 平凉市| 泰宁县| 大连市| 宜良县| 西平县| 霍州市| 石阡县| 克东县| 水城县| 东光县| 怀宁县| 五原县| 南召县| 武定县| 兰坪| 磐安县| 华阴市| 西青区| 婺源县| 营山县| 昌图县| 东安县| 尼木县| 普洱| 甘肃省| 玛多县| 永德县| 陕西省| 申扎县| 越西县| 金川县| 东宁县| 香河县| 柳江县| 普格县| 隆林|