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
360|iDev Concurrency Workshop
Search
sammyd
August 21, 2016
Programming
1
310
360|iDev Concurrency Workshop
Slides accompanying the 360|iDev concurrency workshop from 2016
sammyd
August 21, 2016
Tweet
Share
More Decks by sammyd
See All by sammyd
Core Image: Great when it works
sammyd
1
500
iOS Views & Animations: Learning by stealing
sammyd
1
170
Machine Learning on Mobile—a primer
sammyd
0
96
Core ML: A whistlestop tour
sammyd
1
150
DIY DI
sammyd
2
110
iOSConfSG 2017: Decoding Codable
sammyd
3
190
Machine Learning: deciphering the hype
sammyd
0
130
Notify Me, Notify You. Aha!
sammyd
1
170
SwiftConf 2016: Concurrency on iOS
sammyd
1
170
Other Decks in Programming
See All in Programming
Haskell でアルゴリズムを抽象化する / 関数型言語で競技プログラミング
naoya
17
4.9k
CursorはMCPを使った方が良いぞ
taigakono
1
170
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
0
310
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
560
Team operations that are not burdened by SRE
kazatohiei
1
170
生成AIで日々のエラー調査を進めたい
yuyaabo
0
630
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
310
Railsアプリケーションと パフォーマンスチューニング ー 秒間5万リクエストの モバイルオーダーシステムを支える事例 ー Rubyセミナー 大阪
falcon8823
4
890
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
130
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
310
Result型で“失敗”を型にするPHPコードの書き方
kajitack
4
230
Featured
See All Featured
Writing Fast Ruby
sferik
628
61k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Making the Leap to Tech Lead
cromwellryan
134
9.3k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Why Our Code Smells
bkeepers
PRO
337
57k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Become a Pro
speakerdeck
PRO
28
5.4k
Facilitating Awesome Meetings
lara
54
6.4k
Transcript
Concurrency workshop Sam Davies @iwantmyrealname _ github.com/sammyd git.io/v6waD
concurrency is hard
what is concurrency?
why use concurrency?
common concurrency problems
race condition
Race Condition time Value 1 Thread 1 Thread 2 inc
Race Condition time Value 1 1 Thread 1 Thread 2
inc r1
Race Condition time Value 1 1 1 Thread 1 Thread
2 inc r1 +1
Race Condition time Value 1 1 1 2 Thread 1
Thread 2 inc r1 w2 +1
Race Condition time Value 1 1 1 2 2 Thread
1 Thread 2 inc r1 w2 +1 inc
Race Condition time Value 1 1 1 2 2 2
Thread 1 Thread 2 inc r1 w2 +1 inc r2
Race Condition time Value 1 1 1 2 2 2
2 Thread 1 Thread 2 inc r1 w2 +1 inc r2 +1
Race Condition time Value 1 1 1 2 2 2
2 3 Thread 1 Thread 2 inc r1 w2 +1 inc r2 w3 +1
Race Condition time Value 1 Thread 1 Thread 2 inc
Race Condition time Value 1 1 Thread 1 Thread 2
inc r1 inc
Race Condition time Value 1 1 1 Thread 1 Thread
2 inc r1 inc r1
Race Condition time Value 1 1 1 1 Thread 1
Thread 2 inc r1 inc r1 +1
Race Condition time Value 1 1 1 2 1 Thread
1 Thread 2 inc r1 inc r1 w2 +1
Race Condition time Value 1 1 1 2 1 2
Thread 1 Thread 2 inc r1 +1 inc r1 w2 +1
Race Condition time Value 1 1 1 2 1 2
2 Thread 1 Thread 2 inc r1 w2 +1 inc r1 w2 +1
priority inversion
Priority Inversion time low priority resource
Priority Inversion time low priority resource
Priority Inversion time low medium priority resource
Priority Inversion time low medium high priority resource
Priority Inversion time low medium high priority resource
Priority Inversion time low medium high priority resource
Priority Inversion time low medium high priority resource
deadlock
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
Deadlock time resource1 resource2 Thread 1 Thread 2
$&'( queueueueueue paradigm
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
Tasks & Queues Thread 1 Thread 2 Queue
feeling brave?
a touch more theory
Thread Safety time Value 1111 Thread 1 Thread 2 Thread
3
Thread Safety time Value 1111 Thread 1 Thread 2 r1111
Thread 3
Thread Safety time Value 1111 1112 Thread 1 Thread 2
r1111 w2222 Thread 3
Thread Safety time Value 1111 1112 1122 Thread 1 Thread
2 r1111 w2222 r1122 Thread 3
Thread Safety time Value 1111 1112 1122 1223 Thread 1
Thread 2 r1111 w2222 r1122 w3333 Thread 3 r1223
Thread Safety time Value 1111 1112 1122 1223 2233 Thread
1 Thread 2 r1111 w2222 r1122 w3333 Thread 3 r1223
Thread Safety time Value 1111 1112 1122 1223 2233 2333
Thread 1 Thread 2 r1111 w2222 r1122 r2333 w3333 Thread 3 r1223
Thread Safety time Value 1111 1112 1122 1223 2233 2333
3333 Thread 1 Thread 2 r1111 w2222 r1122 r2333 w3333 Thread 3 r1223
Thread Safety time Value 1111 1112 1122 1223 2233 2333
3333 3333 3333 Thread 1 Thread 2 r1111 w2222 r1122 r2333 w3333 Thread 3 r1223 r3333 r3333
Dispatch Barrier time task task task task task barrier task
task task task task task task task
Dispatch Barrier time read read read read read read write
read read read read read read
alternatives to
promises networkRequest(url, callback: { data in decompressor(data, callback: { image
in imageResizer(image, callback: { small in filterImage(small, callback: { filtered in displayImage(filtered) }) }) }) })
promises promise<int> int error
promises str
promises promise<img> str f
promises promise<img> str error f img
promises promise<img> str error f img error handler
promises promise<img> str error f img g promise<img> error handler
promises promise<img> str error f img g promise<img> error error
handler img
promises promise<img> str error f img g promise<img> error error
handler img
promises networkRequest(url) .then(decompressor) .then(imageResizer) .then({ (image) in return filterImage(image) }).then(displayImage)
.catch({ (error) in print(error) })
imagine the “promise pipeline” accepted a sequence of values…
that’s reactive programming
conclusion
concurrency is hard
you will get it wrong
• raywenderlich.com/videos • git.io/v6waD • @iwantmyrealname