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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
sammyd
August 21, 2016
Programming
330
1
Share
360|iDev Concurrency Workshop
Slides accompanying the 360|iDev concurrency workshop from 2016
sammyd
August 21, 2016
More Decks by sammyd
See All by sammyd
Core Image: Great when it works
sammyd
1
540
iOS Views & Animations: Learning by stealing
sammyd
1
180
Machine Learning on Mobile—a primer
sammyd
0
120
Core ML: A whistlestop tour
sammyd
1
180
DIY DI
sammyd
2
130
iOSConfSG 2017: Decoding Codable
sammyd
3
210
Machine Learning: deciphering the hype
sammyd
0
170
Notify Me, Notify You. Aha!
sammyd
1
190
SwiftConf 2016: Concurrency on iOS
sammyd
1
190
Other Decks in Programming
See All in Programming
GitHubCopilotCLIをはじめよう.pdf
htkym
0
300
AI-DLC Deep Dive
yuukiyo
9
5.1k
実用!Hono RPC2026
yodaka
2
280
PHPer、Cloudflare に引っ越す
suguruooki
1
120
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
2.4k
2026_04_15_量子計算をパズルとして解く
hideakitakechi
0
130
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
160
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
【26新卒研修】OpenAPI/Swagger REST API研修
dip_tech
PRO
0
110
Road to RubyKaigi: Play Hard(ware)
makicamel
1
520
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
230
t *testing.T は どこからやってくるの?
otakakot
1
860
Featured
See All Featured
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
350
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
130
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Making the Leap to Tech Lead
cromwellryan
135
9.8k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
330
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
290
Unsuck your backbone
ammeep
672
58k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
The SEO identity crisis: Don't let AI make you average
varn
0
460
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
KATA
mclloyd
PRO
35
15k
Leo the Paperboy
mayatellez
7
1.7k
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