Supplemental files and examples for this book can be found at http://examples.oreilly.com/0636920020332/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
Preface
With the introduction of multicore devices such as the iPad 2 and the quad-core MacBook Pro, writing multithreaded apps that take advantage of multiple cores on a device has become one of the biggest headaches for developers. Take, for instance, the introduction of iPad 2. On the launch day, only a few applications, basically those released by Apple, were able to take advantage of its multiple cores. Applications like Safari performed very well on the iPad 2 compared to the original iPad, but some third-party browsers did not perform as well as Safari. The reason behind this is that Apple has utilized Grand Central Dispatch (GCD) in Safaris code base. GCD is a low-level C API that allows developers to write multithreaded applications without the need to manage threads at all. All developers have to do is define tasks and leave the rest to GCD.
The trend in the industry is mobility . Mobile devices, whether they are as compact as an iPhone or as strong and full-fledged as an Apple MacBook Pro, have many fewer resources than computers such as the Mac Pro, because all the hardware has to be placed inside the small devices compact bodies. Because of this, it is very important to write applications that work smoothly on mobile devices such as the iPhone. We are not that far away from having quad-core or 8-core smartphones. Once we have 8 cores in the CPU, an app executed on only one of the cores will run tremendously more slowly than an app that has been optimized with a technology such as GCD, which allows the code to be scheduled on multiple cores without the programmer having to manage this synchronization .
Apple is pushing developers away from using threads and is slowly starting to integrate GCD into its various frameworks. For instance, prior to the introduction of GCD in iOS, operations and operation queues used threads. With the introduction of GCD, Apple completely changed the implementation of operations and operation queues by using GCD instead of threads.
This book is written for those of you who want to do what Apple suggests and what seems like the bright future for software development: migrating away from threads and allowing the operating system to take care of threads for you, by replacing thread programming with GCD.
Audience
In this book, I assume that you have a fairly basic understanding of the underlying technologies used in writing iOS and/or Mac OS X applications. We will not be discussing subjects related to Cocoa Touch or Cocoa. We will be using code that works, in principle and GCD layer, both with iOS and Mac OS X. Therefore, you will need to know the basics of Objective-C and your way around basic functionalities utilized by Core Foundation, such as string manipulation and arrays.
Note
OReillys iOS 4 Programming Cookbook is a good source for more about object allocation, arrays, and UI-related code, in case you are looking to broaden your perspective toward iOS programming.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This icon signifies a tip, suggestion, or general note.
Using Code Examples
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Concurrent Programming in Mac OS X and iOS by Vandad Nahavandipoor (OReilly). Copyright 2011 Vandad Nahavandipoor, 9781449305635.
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .
Safari Books Online
Note
Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.
OReilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from OReilly and other publishers, sign up for free at http://my.safaribooksonline.com.