Slide 1

Slide 1 text

Multi - Threading using NSOperation by zeeshan 1 Using Blocks & GCD and Using Asynchronous APIs

Slide 2

Slide 2 text

• Please point out, if anything is wrong. • Please stop me & raise your voice, for: • Going too fast... • Not getting anything... • Any doubts... • Any inclusion from your side. 2

Slide 3

Slide 3 text

Central Processing Unit 3

Slide 4

Slide 4 text

• Why CPU is in the first slide? • How early days of computing works? • What do we understand by cores? • How does these came into existence? • How does it effect our system? 4 CPU

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Clock Speed • What is Clock Speed? • Any problem with it? • Any solution for that? • How to use these cores? How to take advantage of extra cores? 6

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Threads • What is Thread? • What are the problems it solves? (Advantages?) • Does anyone can create thread APIs or any standard follows? • What does Objective C do about thread? 8

Slide 9

Slide 9 text

Key Terms • Process • Thread • Task (Any diagram?) • Concurrent / Non-Concurrent • Thread Safe / Thread Un-Safe (Any diagram?) X

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

NSThread • In which framework is it written? • What is the lifecycle? • What is it based on? • How can we use it? (Any code?) 10

Slide 12

Slide 12 text

Is Thread a Problem • It is a right solution? • What are the cost of using it? • When does problem arise? and Why? • Who gets the burden of it? • How does Thread is different from Process and Task? (Any visual show?) 11

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

NS Operation to the rescue 14

Slide 16

Slide 16 text

NS Operation • When does it introduced? • What is it actually and how it does? • How to use it? • How many times I can use one operation? • What are the features? 15

Slide 17

Slide 17 text

NS Operation II • Manage all threaded code • Model asynchronous operations • KVO Support (Any APIs) • Dependencies (Any APIs) • Priorities (Any APIs) 16

Slide 18

Slide 18 text

NS Operation III • Thread Confinement • Completion Block (Any APIs?) • Cancellation • Concurrent vs Non-Concurrent • Some Caveats... 17

Slide 19

Slide 19 text

NS Operation Queue • Simpler, Name it • Add, Ready & Execute, Cancel | Finish • Pending Operations (Operations vs OperationCounts) • Multiple Queues • Threads & Queues (How many threads?) 18

Slide 20

Slide 20 text

NS Operations Queue II • Queue Width (Any APIs?) • Pause (Suspended) Queues • Cancellation • KVC Compliant (APIs?) • Add Operation with Blocks 19

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Lets Revise 22 • CPU / Clock Speed • Thread Solutions and Problems • Process, Thread, Task, Concurrency, • Safe, Un-Safe, Parallel • Operation, Queue,

Slide 24

Slide 24 text

Demo Use of NS Operation and its queue 23

Slide 25

Slide 25 text

Any Questions? Thank you! http://izeeshan.wordpress.com/ 24

Slide 26

Slide 26 text

25 @zeeshan_khan