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

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.

主站蜘蛛池模板: 宁都县| 阿勒泰市| 富裕县| 郧西县| 鲁山县| 旅游| 聂荣县| 南汇区| 罗定市| 黄骅市| 开远市| 梁河县| 封丘县| 波密县| 广饶县| 洱源县| 方山县| 苍山县| 华宁县| 黔西| 徐州市| 资兴市| 曲靖市| 山阴县| 沾化县| 高唐县| 东方市| 自治县| 凯里市| 且末县| 丹寨县| 稻城县| 宣汉县| 神池县| 德令哈市| 北辰区| 财经| 屯门区| 江北区| 湖北省| 铜陵市|