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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Chein-Wei Huang
August 06, 2015
Technology
43
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
Databricks Appsで実現する社内向けAIアプリ開発の効率化
r_miura
0
230
Babylon.js Japan Activities (2026/4)
limes2018
0
150
Sansanの認証基盤を支えるアーキテクチャとその振り返り
sansantech
PRO
1
150
AIにより大幅に強化された AWS Transform Customを触ってみる
0air
0
280
会社紹介資料 / Sansan Company Profile
sansan33
PRO
16
410k
JAWS DAYS 2026でAIの「もやっと」感が解消された話
smt7174
1
120
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
3
2.1k
FlutterでPiP再生を実装した話
s9a17
0
240
The essence of decision-making lies in primary data
kaminashi
0
230
不確実性と戦いながら見積もりを作成するプロセス/mitsumori-process
hirodragon112
1
180
AWS DevOps Agent or Kiro の使いどころを考える_20260402
masakiokuda
0
140
最大のアウトプット術は問題を作ること
ryoaccount
0
270
Featured
See All Featured
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
250
The Pragmatic Product Professional
lauravandoore
37
7.2k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
170
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
Ruling the World: When Life Gets Gamed
codingconduct
0
190
The untapped power of vector embeddings
frankvandijk
2
1.7k
Making Projects Easy
brettharned
120
6.6k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Navigating Team Friction
lara
192
16k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.4k
The SEO identity crisis: Don't let AI make you average
varn
0
430
Into the Great Unknown - MozCon
thekraken
40
2.3k
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