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
0
33
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
18
C SQLite usage
carlcarl
0
31
MySQL簡易教學
carlcarl
0
100
Other Decks in Technology
See All in Technology
web-application-security
matsuihidetoshi
1
190
MLOpsの「壁」を乗り越える、LINEヤフーの Data Quality as Code
lycorptech_jp
PRO
8
620
LangSmith入門―トレース/評価/プロンプト管理などを担うLLMアプリ開発プラットフォーム
os1ma
5
710
20分で完全に理解するGrafanaダッシュボード
hamadakoji
5
890
いつか使うかも貯金してたらめちゃめちゃ機能が増えてた話
riyaamemiya
0
620
LLM開発・活用の舞台裏@2024.04.25
yushin_n
3
1.2k
Além do else! Categorizando Pokemóns com Pattern Matching no JavaScript
wmsbill
0
710
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
150
M&A戦略を支えるデータマネジメント (MIDAS Tech Study #16 GENDA Komiyama)
kommy339
1
110
MixIT 2024 - Pulumi : Gérer son infra avec son langage de programmation préféré
ju_hnny5
1
120
Grafana x PagerDuty Better Together
jacopen
1
260
.NET Profiler in 2024.
kkamegawa
2
1.5k
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
51k
Rebuilding a faster, lazier Slack
samanthasiow
74
8.2k
Producing Creativity
orderedlist
PRO
338
39k
Git: the NoSQL Database
bkeepers
PRO
423
63k
Building a Modern Day E-commerce SEO Strategy
aleyda
21
6.4k
Designing for humans not robots
tammielis
247
25k
Debugging Ruby Performance
tmm1
70
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
21
1.9k
Optimising Largest Contentful Paint
csswizardry
12
2.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
188
16k
Unsuck your backbone
ammeep
663
57k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
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