Comments (5)
你过誉了:)
查看了部分源码,现在更倾向于Once a runnable G is found, it is executed until it is blocked.
这个说法。
这里有协程执行的函数
// Schedules gp to run on the current M.
// If inheritTime is true, gp inherits the remaining time in the
// current time slice. Otherwise, it starts a new time slice.
// Never returns.
//
// Write barriers are allowed because this is called immediately after
// acquiring a P in several places.
//
//go:yeswritebarrierrec
func execute(gp *g, inheritTime bool) {
协程一旦被调度,没有主动弹出的操作。
协程这部分代码有点复杂,还没仔细看,这个章节也是不完整的。
先暂时搁置,待更详细的分析源码后再修改。
PS:如果你有兴趣,可以深入研究下:)
from goexpertprogramming.
貌似是在函数调用的时候,在栈上做了特殊处理。当发生函数调用,会检查某些条件(具体啥条件我也不知道),如果触发了该条件,则会调度另外一个G运行。
from goexpertprogramming.
貌似是在函数调用的时候,在栈上做了特殊处理。当发生函数调用,会检查某些条件(具体啥条件我也不知道),如果触发了该条件,则会调度另外一个G运行。
对的。正是因为依赖函数调用才能实现G的切换,所以如果函数没有发生函数调用(死循环)时,G就无法被抢占,Go在1.14版本实现的抢占式调度正是解决的这个问题。
from goexpertprogramming.
貌似是在函数调用的时候,在栈上做了特殊处理。当发生函数调用,会检查某些条件(具体啥条件我也不知道),如果触发了该条件,则会调度另外一个G运行。
对的。正是因为依赖函数调用才能实现G的切换,所以如果函数没有发生函数调用(死循环)时,G就无法被抢占,Go在1.14版本实现的抢占式调度正是解决的这个问题。
感谢 @RainbowMango 贡献如此好文,结合你的文章,再看源码如虎添翼
from goexpertprogramming.
哈哈,你这么说我很高兴,能帮助别人看源码也算没白费力。
from goexpertprogramming.
Related Issues (20)
- [建议] 5.3 context可以把例子前移么 HOT 2
- [勘误]反馈一个第2章第2.2节的示例运行结果错误 HOT 3
- [勘误]反馈一个第1章第3节的内容错误 HOT 9
- [勘误]反馈一个第1章第3.3节的流程图 HOT 2
- [勘误]反馈一个第1章第1.2节的运行结果错误 HOT 3
- [勘误]反馈一个第2章第2.3节的错别字 HOT 1
- [勘误]反馈一个第一章第2节的错别字 HOT 1
- [勘误]反馈一个第M章第N节的错别字 HOT 2
- [勘误]反馈一个第3章第1节的错别字 HOT 7
- 关于3.2G0系统调用描述问题探讨 HOT 1
- [勘误]反馈一个第一章第二节中关于slice扩容问题 HOT 7
- [勘误]反馈一个第5章第3节的context描述错误 HOT 6
- [勘误]反馈一个第4章 4.1内存分配的配图问题 HOT 1
- [勘误]反馈一个第1章第3节的问题 HOT 3
- 关于13.1节的疑问
- 关于13.1节的疑问 HOT 5
- [勘误]反馈一个第1章第2节,关于切片简单表达式的 cap 取值问题 HOT 2
- [勘误]反馈一个第1章第3节的错别字 HOT 2
- [勘误]反馈一个第2章第2节的错别字 HOT 1
- [勘误]反馈一个第一章第一节的错误 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goexpertprogramming.