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
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
[Journal club] Thinking in Space: How Multimodal Large Language Models See, Remember, and Recall Spaces
keio_smilab
PRO
0
110
datadog-incident-management-intro
tetsuya28
0
120
Giving Tuesday Auctria Set-Up 2025
auctria
PRO
0
100
GCASアップデート(202508-202510)
techniczna
0
340
Snowflakeとdbtで加速する 「TVCMデータで価値を生む組織」への進化論 / Evolving TVCM Data Value in TELECY with Snowflake and dbt
carta_engineering
0
150
어떤 개발자가 되고 싶은가?
arawn
1
430
今のコンピュータ、AI にも Web にも 向いていないので 作り直そう!!
piacerex
0
630
Digitization部 紹介資料
sansan33
PRO
1
5.8k
書籍『実践 Apache Iceberg』の歩き方
ishikawa_satoru
0
470
ソフトウェア品質を支える テストとレビュー再考 / 吉澤 智美さん
findy_eventslides
0
100
251029 JAWS-UG AI/ML 退屈なことはQDevにやらせよう
otakensh
0
190
AIで急増した生産「量」の荒波をCodeRabbitで乗りこなそう
moongift
PRO
0
480
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Gamification - CAS2011
davidbonilla
81
5.5k
Faster Mobile Websites
deanohume
310
31k
Documentation Writing (for coders)
carmenintech
76
5.1k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Agile that works and the tools we love
rasmusluckow
331
21k
What's in a price? How to price your products and services
michaelherold
246
12k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
720
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
54k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
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