当前位置:网站首页>Go language concurrency model mpg model
Go language concurrency model mpg model
2022-06-24 14:21:00 【Crying while learning】

Go There are three important components in the language scheduler :M、P、G
- M yes Machine, System threads . It is managed by the operating system ,goroutine Just run in M Above .M It's a big structure , It maintains small object memory cache(mcache)、 Currently executed goroutine、 Random number generator and so on .
- P yes Processor, Represents the program execution context 、 processor .P It can be seen as a local scheduler ,P Will wait to run G And M Docking . It maintains a goroutine queue , namely runqueue.GO The runtime system will make M and P Build or disconnect in time .
- G yes goroutine, There can be multiple . It contains the stack 、 Instruction pointer 、 Waiting place channel, And other effects on scheduling goroutine Important information .
MPG Model

Ongoing goroutine For blue , In a state of pending execution goroutine It's gray . Execu goroutine All stored in runqueue in ,P Maintainer this runqueue. Whenever by new goroutine Be performed , Will join in runqueue.
Actually go Language runtime systems did not exist in the early days P The concept ,go The language scheduler directly puts G Assign to the appropriate M On . But the problem with this is G The concurrent runtime needs to apply for resources from the system , It will cause performance loss .
from go Of 1.1 Version start , Add... To the runtime system P, from P To manage G object ,M Want to run G You need to bind P. The advantage of this is , Can be in P Object to apply for some system resources in advance , When G When you need it, ask your P To apply .P If resources are not enough , To apply for resources from the global , And will take some more resources for the later G To use the .
and P Decoupled M and G The relationship between . If there is G There's a blockage ,P You can take other G With the new M Binding , bring G It always works in time , To improve concurrency .
goroutine happening

M1 May be newly created , It may also be taken directly from the cache .
When G0 When blocking occurs ,P Will be with the current M0、G0 Unbundling .M1 And P Binding , Carry on P Others under goroutine.
runqueue Execution completed
When Processor Of runqueue Execution completed , It's empty time . He will learn from others Processor Steal half of the goroutine.

边栏推荐
- 取消冒泡
- [deep learning] storage form of nchw, nhwc and chwn format data
- GO语言-init()函数-包初始化
- 【无标题】
- [untitled]
- Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers
- 4个不可不知的“安全左移”的理由
- Maximum path sum in binary tree [handle any subtree, then handle the whole tree]
- Common sense knowledge points
- How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup
猜你喜欢
随机推荐
GO语言-init()函数-包初始化
AntD checkbox,限制选中数量
Defoaming
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
21set classic case
4个不可不知的“安全左移”的理由
Explore cloud native databases and take a broad view of future technological development
【ansible问题处理】远程执行用户环境变量加载问题
NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)
win10系统问题
unity 等高线创建方法
Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
Rongyun communication has "hacked" into the heart of the bank
R语言plotly可视化:使用plotly可视化数据划分后的训练集和测试集、使用不同的形状标签表征、训练集、测试集、以及数据集的分类标签(Display training and test split
初识云原生安全:云时代的最佳保障
v-for 中 key的作用和原理
R语言plotly可视化:可视化模型在整个数据空间的分类轮廓线(等高线)、meshgrid创建一个网格,其中每个点之间的距离由mesh_size变量表示、使用不同的形状标签表征、训练、测试及分类标签
OpenHarmony 1
10_那些格调很高的个性签名
Halcon 绘制区域 到图片中





![[leetcode] 10. Regular expression matching](/img/a9/4cdf8d46068a2d7ea6ac212f416157.png)



