Slide 1

Slide 1 text

Multi - Threading by zeeshan 1

Slide 2

Slide 2 text

CPU Why do we have n number of Core(s)? 2

Slide 3

Slide 3 text

nothing is limitless & every problem has a solution Clock Speed A time unit 3

Slide 4

Slide 4 text

Thread ‘Kernel-level’ + ‘Application-level’ Data Structures An application can use multiple cores by creating multiple threads. 4 Parallel Computation Asynchronous Solution

Slide 5

Slide 5 text

Key Terms • Process • Thread (Safe / Un-Safe) • Task • Concurrent / Non-Concurrent • Concurrent vs Parallel 5

Slide 6

Slide 6 text

NSThread POSIX (Mavericks is 100% POSIX conferment) 6 Life Cycle

Slide 7

Slide 7 text

Hazard of Threaded Programming • UIKit access • Database access • Stale result • Cancellation • De-allocation 7

Slide 8

Slide 8 text

Solutions • Operations (Current Session) • GCD (Next Session) • Notification Queue • Asynchronous (Hopefully Next to Next Session) • Timers 8

Slide 9

Slide 9 text

NS Operation to the rescue 9

Slide 10

Slide 10 text

NS Operations • Manage all threaded code • Model asynchronous operations • KVO Support • Dependencies • Priorities 10

Slide 11

Slide 11 text

NS Operation II • Thread Confinement • Completion Block • Cancellation • Concurrent vs Non-Concurrent • Some Caveats... 11

Slide 12

Slide 12 text

NS Operation Queue • Simpler, Name it • Add, Ready & Execute, Cancel | Finish • Pending Operations • Multiple Queues • Threads & Queues 12

Slide 13

Slide 13 text

NS Operations Queue II • Queue Width • Pause (Suspended) Queues • Cancellation • KVC Compliant • Add Operation with Blocks 13

Slide 14

Slide 14 text

NS Operations - Use • Blocks • Concrete sub classes • Selector • Block • User defined sub classes 14

Slide 15

Slide 15 text

References: • Multithreading Using NSOperation (http:// izeeshan.wordpress.com/2014/08/17/multi-threading- using-nsoperation/) • Concurrency Programming Guide • Threading Programming Guide • API References 15

Slide 16

Slide 16 text

Any Questions? Thank you! @zeeshan_khan http://izeeshan.wordpress.com/ 16

Slide 17

Slide 17 text

17 @zeeshan_khan