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
60
0
Share
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
25
C SQLite usage
carlcarl
0
37
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
新規事業を牽引する技術選定 〜フルスタックTypeScript開発の実践事例〜
nullnull
1
170
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
2
1.4k
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
チームで実践する AI-DLC 思考の軌跡を残すチェックポイント設計
belongadmin
0
1.6k
「嘘をつくテスト」の失敗例から学ぶ 良いテストコード #frontend_phpcon_do
asumikam
0
140
『家族アルバム みてね』における インシデント対応との向き合い方 / Approach incident response in Family Album
kohbis
2
290
AI時代の私の技術インプットとアウトプット術
tonkotsuboy_com
16
8.2k
大学生が本気でDatabricksを活用してDiscordサークルをデータ駆動させてみた
phantomjuju
1
330
Ruby::Boxでできること、Refinementsでできること
joker1007
3
370
最低限これだけ押さえれ大丈夫_Claude Enterprise/Team企業展開ガバナンス入門
tkikuchi
1
660
TROCCOで始めるクラウドコストを民主化するためのFinOps
tk3fftk
3
540
個人の発見を、組織の知恵に 〜生成AI活用を"探索"から"組織の仕組み"へ〜
kintotechdev
2
490
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
The untapped power of vector embeddings
frankvandijk
2
1.7k
How to Talk to Developers About Accessibility
jct
2
210
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
200
The Limits of Empathy - UXLibs8
cassininazir
1
340
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
250
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
Test your architecture with Archunit
thirion
1
2.3k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
440
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