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
24
C SQLite usage
carlcarl
0
35
MySQL簡易教學
carlcarl
0
120
Other Decks in Technology
See All in Technology
GSIが複数キー対応したことで、俺達はいったい何が嬉しいのか?
smt7174
3
150
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
140
予期せぬコストの急増を障害のように扱う――「コスト版ポストモーテム」の導入とその後の改善
muziyoshiz
1
1.8k
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
今日から始めるAmazon Bedrock AgentCore
har1101
4
400
広告の効果検証を題材にした因果推論の精度検証について
zozotech
PRO
0
150
20260204_Midosuji_Tech
takuyay0ne
1
140
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
220
顧客の言葉を、そのまま信じない勇気
yamatai1212
1
350
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
2
340
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
160
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
320
What's in a price? How to price your products and services
michaelherold
247
13k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Optimizing for Happiness
mojombo
379
71k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.3k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
sira's awesome portfolio website redesign presentation
elsirapls
0
150
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