Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Multithreading using NSOperation - 2

Multithreading using NSOperation - 2

Zeeshan Khan

August 20, 2014
Tweet

More Decks by Zeeshan Khan

Other Decks in Programming

Transcript

  1. • 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
  2. • 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
  3. 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
  4. Thread ‘Kernel-level’ + ‘Application-level’ Data Structures An application can use

    multiple cores by creating multiple threads. 7 Parallel Computation Asynchronous Solution
  5. 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
  6. Key Terms • Process • Thread • Task (Any diagram?)

    • Concurrent / Non-Concurrent • Thread Safe / Thread Un-Safe (Any diagram?) X
  7. NSThread • In which framework is it written? • What

    is the lifecycle? • What is it based on? • How can we use it? (Any code?) 10
  8. 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
  9. Hazard of Threaded Programming • UIKit access • Database access

    • Stale result • Cancellation • De-allocation 12
  10. Solutions • Operations (Current Session) • GCD (Next Session) •

    Notification Queue • Asynchronous (Hopefully Next to Next Session) • Timers 13
  11. 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
  12. NS Operation II • Manage all threaded code • Model

    asynchronous operations • KVO Support (Any APIs) • Dependencies (Any APIs) • Priorities (Any APIs) 16
  13. NS Operation III • Thread Confinement • Completion Block (Any

    APIs?) • Cancellation • Concurrent vs Non-Concurrent • Some Caveats... 17
  14. NS Operation Queue • Simpler, Name it • Add, Ready

    & Execute, Cancel | Finish • Pending Operations (Operations vs OperationCounts) • Multiple Queues • Threads & Queues (How many threads?) 18
  15. NS Operations Queue II • Queue Width (Any APIs?) •

    Pause (Suspended) Queues • Cancellation • KVC Compliant (APIs?) • Add Operation with Blocks 19
  16. NS Operations - Use • Blocks • Concrete sub classes

    • Selector • Block • User defined sub classes 20
  17. 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
  18. Lets Revise 22 • CPU / Clock Speed • Thread

    Solutions and Problems • Process, Thread, Task, Concurrency, • Safe, Un-Safe, Parallel • Operation, Queue,