Concurrent Programming in iOS

Post on 11-Apr-2017

46 views 0 download

transcript

Concurrent Programming

Sam Mejlumyan

What about we’ll talk

• What is Concurrent Programming

• Concurrency APIs on iOS

• Challenges of Concurrent Programming

Concurrent vs. Parallel

Concurrency APIs on iOS

• Threads

• GCD

• Operation Queues

• Run Loops

Threads

• POSIX thread API

• The basic for GCD and Operation queues

• Objective-C wrapper – NSThread

Pthreads• Thread management - creating, joining threads

• Mutexes

• Condition variables

• Synchronization between threads using read/write locks and barriers

• Use when create application for different platform

Objective-C wrapper around pthreads

NSThread

GCD

• Low-Level API

• You don’t interact with threads directly

• Five different queues

GCD

GCD

Quality of Service• userInteractive

• userInitiated

• default

• utility

• background

• unspecified ••

Operation Queue features

• maxConcurrentOperationCount property

• sorting of operations

• specify dependencies between operations

• cancelation mechanism

• KVO

• state of operation

Sharing of ResourcesRace condition

Mutual Exclusion

Dead Locks

Priority Inversion

Conclusion

• pull out the data on the main thread

• use an operation queue to do the actual work in the background

• finally get back onto the main queue

vk.com/s.mejl