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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Chein-Wei Huang
August 06, 2015
Technology
63
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
38
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
螺旋型キャリアの生存戦略 / kinoko-conf2026
rakus_dev
1
900
20260619 私の日常業務での生成 AI 活用
masaruogura
1
250
AIネイティブな開発のサプライチェーンリスク対策 〜激動の開発現場でリスクに立ち向かう〜【ZennFes】
cscengineer
PRO
2
150
SteampipeとExcel Power QueryでAWS構成定義書の作成を自動化する
jhashimoto
0
170
「ビジネスがわかるエンジニア」とは何か?
ryooob
0
260
AI-DLCを “そのまま導入しなかった”話 ~組織に合わせてアジャストした 私たちの実践共有~
hiroramos4
PRO
1
410
iOS アプリの「これって不具合ですか?」を AI に調べてもらう
miichan
0
140
脱SaaS!FDEを支えるプロビジョニングと分離設計
knih
0
260
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
260
入門!AWS Blocks
ysuzuki
1
180
2026年6月23日 Syncable Tech + Start Python Club にて
hamukazu
0
150
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.8k
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
280
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
170
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
The SEO Collaboration Effect
kristinabergwall1
1
490
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
The Invisible Side of Design
smashingmag
301
52k
Done Done
chrislema
186
16k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
180
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
Visualization
eitanlees
152
17k
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