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
290
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
480
iOS Views & Animations: Learning by stealing
sammyd
1
160
Machine Learning on Mobile—a primer
sammyd
0
85
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
160
Other Decks in Programming
See All in Programming
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
4
1.1k
From Translations to Multi Dimension Entities
alexanderschranz
2
130
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
330
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
命名をリントする
chiroruxx
1
390
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Zoneless Testing
rainerhahnekamp
0
120
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
100
CSC305 Lecture 26
javiergs
PRO
0
140
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
How to train your dragon (web standard)
notwaldorf
88
5.7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
97
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Git: the NoSQL Database
bkeepers
PRO
427
64k
We Have a Design System, Now What?
morganepeng
51
7.3k
Site-Speed That Sticks
csswizardry
2
190
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
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