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
300
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
490
iOS Views & Animations: Learning by stealing
sammyd
1
160
Machine Learning on Mobile—a primer
sammyd
0
87
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
160
SwiftConf 2016: Concurrency on iOS
sammyd
1
170
Other Decks in Programming
See All in Programming
CRE Meetup!ユーザー信頼性を支えるエンジニアリング実践例の発表資料です
tmnb
0
590
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
3
1.1k
「影響が少ない」を自分の目でみてみる
o0h
PRO
1
560
AHC045_解説
shun_pi
0
400
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
2.3k
Denoでフロントエンド開発 2025年春版 / Frontend Development with Deno (Spring 2025)
petamoriken
1
1.3k
リアルタイムレイトレーシング + ニューラルレンダリング簡単紹介 / Real-Time Ray Tracing & Neural Rendering: A Quick Introduction (2025)
shocker_0x15
1
270
海外のアプリで見かけたかっこいいTransitionを真似てみる
shogotakasaki
1
150
AHC 044 混合整数計画ソルバー解法
kiri8128
0
320
PHPバージョンアップから始めるOSSコントリビュート / how2oss-contribute
dmnlk
1
380
コンテナでLambdaをデプロイするときに知っておきたかったこと
_takahash
0
170
PHPer's Guide to Daemon Crafting Taming and Summoning
uzulla
2
1.2k
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1369
200k
GitHub's CSS Performance
jonrohan
1030
460k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Typedesign – Prime Four
hannesfritz
41
2.6k
BBQ
matthewcrist
88
9.6k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
8
720
The Language of Interfaces
destraynor
157
24k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
370
Why Our Code Smells
bkeepers
PRO
336
57k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
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