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

Multi-Threading using NSOperation

Multi-Threading using NSOperation

Zeeshan Khan

August 18, 2014
Tweet

More Decks by Zeeshan Khan

Other Decks in Programming

Transcript

  1. Thread ‘Kernel-level’ + ‘Application-level’ Data Structures An application can use

    multiple cores by creating multiple threads. 4 Parallel Computation Asynchronous Solution
  2. Key Terms • Process • Thread (Safe / Un-Safe) •

    Task • Concurrent / Non-Concurrent • Concurrent vs Parallel 5
  3. Hazard of Threaded Programming • UIKit access • Database access

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

    Notification Queue • Asynchronous (Hopefully Next to Next Session) • Timers 8
  5. NS Operations • Manage all threaded code • Model asynchronous

    operations • KVO Support • Dependencies • Priorities 10
  6. NS Operation II • Thread Confinement • Completion Block •

    Cancellation • Concurrent vs Non-Concurrent • Some Caveats... 11
  7. NS Operation Queue • Simpler, Name it • Add, Ready

    & Execute, Cancel | Finish • Pending Operations • Multiple Queues • Threads & Queues 12
  8. NS Operations Queue II • Queue Width • Pause (Suspended)

    Queues • Cancellation • KVC Compliant • Add Operation with Blocks 13
  9. NS Operations - Use • Blocks • Concrete sub classes

    • Selector • Block • User defined sub classes 14