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
68
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
26
C SQLite usage
carlcarl
0
39
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
AIエージェントの開発・提供におけるセキュリティリスクの論点と対策
flatt_security
1
560
振り返りこそエンジニアの本領
negima
0
270
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
110
設計の世代交代を乗り越える、14年続くAndroidアプリの開発戦略
sansantech
PRO
1
120
Benchmarking Vector Databases: pgvector vs. LanceDB
tsho
0
140
どんな手を使っても絶対間に合わせるスケジューラ
asari194617
0
1.6k
推論の観測、できていますか? 〜 Google Cloud Gemini Enterprise Agent Platformで 3つの Gemini モデルを実測して踏んだ、評価の罠 〜
shukob
PRO
0
140
DGX Sparkを2台使って いろいろ動かす話
sonoda_mj
1
130
書籍『生成AIの安全性入門』の入門
wataoka
0
210
ブラウザアプリの継続的パフォーマンスモニタリング (序) / Continuous Browser Application Performance Monitoring; Act 1
moznion
0
110
【試作】IoT x AIエージェント
happysamurai294
0
100
AI時代におけるプロダクト横断勉強会の設計
zozotech
PRO
0
150
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Test your architecture with Archunit
thirion
2
2.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
990
Unsuck your backbone
ammeep
672
58k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
290
The SEO Collaboration Effect
kristinabergwall1
1
550
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
500
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
Building the Perfect Custom Keyboard
takai
2
860
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
440
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
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