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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
ブロックテーマでサイトをリニューアルした話 / 2026-01-31 Kansai WordPress Meetup
torounit
0
450
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
290
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
180
日本の85%が使う公共SaaSは、どう育ったのか
taketakekaho
1
140
変化するコーディングエージェントとの現実的な付き合い方 〜Cursor安定択説と、ツールに依存しない「資産」〜
empitsu
4
1.3k
AWS Network Firewall Proxyを触ってみた
nagisa53
0
150
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
13k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
42k
Context Engineeringが企業で不可欠になる理由
hirosatogamo
PRO
3
440
SREが向き合う大規模リアーキテクチャ 〜信頼性とアジリティの両立〜
zepprix
0
410
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
340
Meshy Proプラン課金した
henjin0
0
250
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
Producing Creativity
orderedlist
PRO
348
40k
BBQ
matthewcrist
89
10k
Designing for Performance
lara
610
70k
Building AI with AI
inesmontani
PRO
1
680
4 Signs Your Business is Dying
shpigford
187
22k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Color Theory Basics | Prateek | Gurzu
gurzu
0
190
sira's awesome portfolio website redesign presentation
elsirapls
0
140
Mind Mapping
helmedeiros
PRO
0
78
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