Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
C Coroutine
Search
Chein-Wei Huang
August 06, 2015
Technology
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
C Coroutine
Chein-Wei Huang
August 06, 2015
Transcript
9 slides
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
More Decks by Chein-Wei Huang
See All by Chein-Wei Huang
JavaScript Patterns chapter 8 of mine
carlcarl
0
27
C SQLite usage
carlcarl
0
42
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
アラートを見直していたら営業組織への理解にちょっとだけ繋がった話
z63d
1
210
Linuxネットワークスタック進化の軌跡: 過去10年の歩みと最新トレンド
orimanabu
4
750
MCPでネットワーク障害調査を自動化する前に直すべき3つのこと
yama3133
1
580
自動計装なしでECSサービスをApplication Signalsに載せるまで
ota1022
2
320
SREのためのFinOps入門
muziyoshiz
3
1.6k
Sonnetだけで業務はまわる?
kintotechdev
1
140
Go初心者のクラウドエンジニアが、デプロイを通して旨味を知っていく話
ryudai
1
230
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
470
会社説明資料_最新版
demaecan
0
32k
文書画像からの情報抽出を行うエージェントを、軌跡の正解データ無しで作れるか
sansantech
PRO
2
190
SORACOM × AWS IoT Core でSREする
butadora
0
110
マネージャーをエスパーにしない マネジメントされる側から始める、働きやすい現場づくり
comi190327
1
750
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
590
Facilitating Awesome Meetings
lara
57
7.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
AI: The stuff that nobody shows you
jnunemaker
PRO
12
1.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
560
Chasing Engaging Ingredients in Design
codingconduct
0
400
Marketing to machines
jonoalderson
1
6k
Design in an AI World
tapps
1
390
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
240
ラッコキーワード サービス紹介資料
rakko
5
5.9M
Faster Mobile Websites
deanohume
310
32k
How to make the Groovebox
asonas
2
2.6k