Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

5. Concurrency > 5.13. Running Tasks Asynchronously with Operations

5.13. Running Tasks Asynchronously with Operations

Problem

You want to execute operations concurrently.

Solution

Use operation queues. Alternatively, subclass NSOperation and detach a new thread on the main method.

Discussion

As mentioned in Recipe 5.12, operations, by default, run on the thread that calls the start method. Usually we start operations on the main thread, but at the same time we expect the operations to run on their own threads and not take the main thread’s time slice. The best solution for us would be to use operation queues. However, if you want to manage your operations manually, which I do not recommend, you can subclass NSOperation and detach a new thread on the main method. Please refer to Recipe 5.16 for more information about detached threads.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial