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
44
0
Share
C Coroutine
Chein-Wei Huang
August 06, 2015
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
Anthropic「Long-running a gents」をGeminiで再現してみた
tkikuchi
0
770
小さいVue.jsを30分で作る
hal_spidernight
0
130
フロントエンドの相手が変わった - AIが加わったWebの新しいインターフェース設計
azukiazusa1
31
9.8k
M5Stack CoreS3とZephyr(RTOS)で Edge AIっぽいことしてみた
iotengineer22
0
430
AI活用時代の事業判断高度化を導くエンジニアリング基盤 / 20260424 Atsushi Funahashi
shift_evolve
PRO
2
130
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
530
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
4
6.7k
Percolatorを廃止し、マルチ検索サービスへ刷新した話 / Search Engineering Tech Talk 2026 Spring
visional_engineering_and_design
0
280
Forget technical debt
ufried
0
160
AI時代に越境し、 組織を変えるQAスキルの正体 / QA Skills for Transforming an Organization
mii3king
5
3.5k
AIが盛んな時代に 技術記事を書き始めて起きた私の中での小さな変化
peintangos
0
350
ServiceによるKubernetes通信制御ーClusterIPを例に
miku01
1
120
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.4k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
140
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.4k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
230
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
15
Everyday Curiosity
cassininazir
0
200
Balancing Empowerment & Direction
lara
6
1.1k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
350
Evolving SEO for Evolving Search Engines
ryanjones
0
180
Measuring & Analyzing Core Web Vitals
bluesmoon
9
820
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