Comments (6)
看代码终于明白了。以example_copustack.cpp为例,它在一个线程中分配了128个栈,则128n(n>=0)号协程都使用0号栈,128n+1使用1号栈,以此类推。
当协程运行时,运行到co_swap,如果0号协程是第一次使用pending_co->stack_mem->ocupy_co,则其为null,此时将pending_co赋值给它;如果第二次128号协程过来运行,判断出这个变量其实保存的是0号协程的内容,此时,需要执行copy操作,把0号协程的栈信息保存到malloc的空间。
感觉这样并不能节省多少空间啊。。。虽然运行栈的空间变小了,但是新赠了额外保存协程信息的内存,会不会得不偿失啊?
from libco.
这个优化点,主要在于,栈的内存峰值不一定是栈切换时发生的。
例如,
栈a的内存峰值为8k,发生切换时只需使用4k,那使用共享的可以节约4k。
from libco.
这个感觉优化有限,因为并不能控制一定在4k的时候切换,如果切换的时候就是8k,那不是还浪费了8k的空间存储?
from libco.
1.不会存在浪费
2.是否能节省,取决于切换时是否峰值。正常来说,一个协程不可能每次切换都处于峰值。
这个是针对场景性的优化,当然不能保证每份代码都起作用,但是越复杂的逻辑这个效果会越明显。
from libco.
学习了,非常感谢!
from libco.
close
from libco.
Related Issues (20)
- CFLAGS includes redundant -Wall which has no effect
- build error on macOS
- 在windows平台上使用msvc编译失败. HOT 2
- 请教用cpprestsdk与协程配合堵塞的问题 HOT 5
- 【BUG Report】__i386__场景下协程共享栈有问题 HOT 2
- undefined reference to `dlsym' HOT 1
- 是否可以在libco的协程内使用fork后exec?
- CMakeList 缺少文件导致编译错误
- libco性能咋样?有人测过吗
- -
- non-x86 arch support HOT 1
- 跨平台协程库 HOT 4
- CMakeLists.txt有误 HOT 2
- 如果应用本身已经使用了epoll,会和libco冲突吗?
- 在example_echosvr示例中多进程共享的栈g_readwrite为什么不需要加进程锁
- coctx_make 是否存在无效代码 HOT 1
- Makefile dependency errors
- if a variable defined by CO_ROUTINE_SPECIFIC is referenced in multiple cpps, multiple instances of the variable will be generated under release build HOT 1
- 期望支持一下跨平台,比如Windows
- 协程栈切换时未保存浮点/SIMD寄存器
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 libco.