当前位置:网站首页>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.

边栏推荐
- 成功解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This versi
- Halcon draw area into picture
- 取消冒泡
- IDEA连接mysql自定义生成实体类代码
- Puzzle (016.2) finger painting Galaxy
- 在宇宙的眼眸下,如何正确地关心东数西算?
- Rongyun communication has "hacked" into the heart of the bank
- PgSQL queries the largest or smallest data of a field in a group
- Generate binary tree according to preorder & inorder traversal [partition / generation / splicing of left subtree | root | right subtree]
- Kotlin coordination channel
猜你喜欢

文本对比学习综述

box-sizing
![NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)](/img/b0/85ac6274b239e42c9543fa296df456.png)
NPM package [details] (including NPM package development, release, installation, update, search, uninstall, view, version number update rules, package.json details, etc.)

Second, the examinee must see | consolidate the preferred question bank to help the examinee make the final dash

Linux 安装 CenOS7 MySQL - 8.0.26

专精特新“小巨人”再启动,“企业上云”数字赋能

Unity 热力图建立方法

SAP Marketing Cloud 功能概述(三)

Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!

How to solve the problem that iterative semi supervised training is difficult to implement in ASR training? RTC dev Meetup
随机推荐
leetcode:1504. Count the number of all 1 sub rectangles
一文搞定 UDP 和 TCP 高频面试题!
Unit contour creation method
Defeat the binary tree!
【深度学习】NCHW、NHWC和CHWN格式数据的存储形式
`Thymeleaf ` template engine comprehensive analysis
Online text entity extraction capability helps applications analyze massive text data
六石管理学:垃圾场效应:工作不管理,就会变成垃圾场
C language ---18 function (user-defined function)
[untitled]
【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
3环杀掉360安全卫士进程
百度地图API绘制点及提示信息
leetcode:1504. 统计全 1 子矩形的个数
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
In the eyes of the universe, how to correctly care about counting East and West?
Kotlin shared mutable state and concurrency
Method of inputting dots under letters in markdown/latex
专精特新“小巨人”再启动,“企业上云”数字赋能
从谭浩强《C程序设计》上摘录的ASCII码表(常用字符与ASCII代码对照表)