$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
C Coroutine
Search
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
23
C SQLite usage
carlcarl
0
35
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
AWS Trainium3 をちょっと身近に感じたい
bigmuramura
1
140
意外とあった SQL Server 関連アップデート + Database Savings Plans
stknohg
PRO
0
300
EM歴1年10ヶ月のぼくがぶち当たった苦悩とこれからへ向けて
maaaato
0
270
グレートファイアウォールを自宅に建てよう
ctes091x
0
140
モダンデータスタック (MDS) の話とデータ分析が起こすビジネス変革
sutotakeshi
0
450
生成AI時代におけるグローバル戦略思考
taka_aki
0
120
安いGPUレンタルサービスについて
aratako
2
2.7k
Challenging Hardware Contests with Zephyr and Lessons Learned
iotengineer22
0
170
AWS CLIの新しい認証情報設定方法aws loginコマンドの実態
wkm2
6
690
AWS Bedrock AgentCoreで作る 1on1支援AIエージェント 〜Memory × Evaluationsによる実践開発〜
yusukeshimizu
6
380
第4回 「メタデータ通り」 リアル開催
datayokocho
0
120
AI駆動開発における設計思想 認知負荷を下げるフロントエンドアーキテクチャ/ 20251211 Teppei Hanai
shift_evolve
PRO
2
310
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Building Adaptive Systems
keathley
44
2.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Practical Orchestrator
shlominoach
190
11k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.3k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Agile that works and the tools we love
rasmusluckow
331
21k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.2k
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