Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
C Coroutine
Search
Chein-Wei Huang
August 06, 2015
Technology
0
43
C Coroutine
Chein-Wei Huang
August 06, 2015
Tweet
Share
More Decks by Chein-Wei Huang
See All by Chein-Wei Huang
JavaScript Patterns chapter 8 of mine
carlcarl
0
24
C SQLite usage
carlcarl
0
35
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
予期せぬコストの急増を障害のように扱う――「コスト版ポストモーテム」の導入とその後の改善
muziyoshiz
1
1.8k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
68k
ZOZOにおけるAI活用の現在 ~開発組織全体での取り組みと試行錯誤~
zozotech
PRO
5
5k
Context Engineeringが企業で不可欠になる理由
hirosatogamo
PRO
3
540
プロポーザルに込める段取り八分
shoheimitani
1
190
配列に見る bash と zsh の違い
kazzpapa3
1
130
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
430
データ民主化のための LLM 活用状況と課題紹介(IVRy の場合)
wxyzzz
2
700
こんなところでも(地味に)活躍するImage Modeさんを知ってるかい?- Image Mode for OpenShift -
tsukaman
0
120
SREチームをどう作り、どう育てるか ― Findy横断SREのマネジメント
rvirus0817
0
160
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
300
OCI Database Management サービス詳細
oracle4engineer
PRO
1
7.4k
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
0
140
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Test your architecture with Archunit
thirion
1
2.1k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
180
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
110
Code Reviewing Like a Champion
maltzj
527
40k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Transcript
C Coroutine Multiple tasks with single CPU
Outline 1. Process, Thread, Event 2. Coroutine 3. C Couroutline
Library 4. Protothread 5. Reference
Process, Thread, Event • Process & Thread ◦ Resource cost
◦ Resource lock ◦ process1/thread1(io1,do1), process2/thread2(io2, do2) • Event ◦ Lots of nested callbacks ◦ set(io1,do1); set(io2,do2); loop_event();
Coroutine foo() { static int i; for(i = 0; i
< 10; i++){ printf(“%d\n”, i); yield i; } } foo(); // 0 foo(); // 1
Coroutine a() { a_init(); while(!io1()) yield; do1(); } b() {
b_init(); while(!io2()) yield; do2(); } loop{a(); b();};
C Coroutine Library • Protothread ◦ switch case • State
threads ◦ longjmp + setjmp • couroutine ◦ ucontext
Protothread int function(void) { static int i, state; switch (state)
{ case 0: /* start of function */ for (i = 0; i < 10; i++) { state = __LINE__ + 2; /* so we will come back to "case __LINE__" */ return i; case __LINE__:; /* resume control straight after the return */ } } }
Protothread
Reference • http://programmers.stackexchange. com/questions/147182/ • http://coolshell.cn/articles/10975.html • http://coolshell.cn/articles/12012.html