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 Safari’s 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

O’Reilly’s 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 you’re 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 O’Reilly 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 product’s 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 (O’Reilly). 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.

O’Reilly 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 O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9781449305635

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

Content Updates

June 3, 2011

  • Minor technical fix: In the first example of block objects, two parameters were passed to a block object, but only one was used in the subtract operation.

Acknowledgments

Working with O’Reilly to write books has always been a pleasure and this book is not an exception. I must say I am very fortunate to have fantastic friends and a fantastic support team around me, for without them, I wouldn’t be the person I am today and you wouldn’t be reading this book.

Andy Oram and Brian Jepson have been incredibly supportive of my efforts and have, for the fourth time, given me a chance to reach out to those who want to be educated further in cutting-edge technologies such as Grand Central Dispatch.

I am grateful for my wonderful friends who have been a continuous source of inspiration and support. Thanks to my friends and colleagues Sushil Shirke, Shency Revindran, Angela Rory, Chris Harman, Natalie Szrajber, Simon Whitty, Shaun Puckrin, Gary McCarville, Mark Harris, and Kirk Pattinson.

I would also like to thank everybody from O’Reilly who has helped me so far with my sometimes-incredibly-annoying requests. Thanks to Sarah Schneider for helping me with SVN setup and other technical DocBook questions. Thanks to Rachel James for helping me manage readers’ requests for my existing books. A big thank you goes to Betsy Waliszewski and Gretchen Giles of O’Reilly for arranging a three-day half-price offer on many O’Reilly titles to help with Japanese disaster relief. With all you wonderful readers’ help, O’Reilly donated $200,000 to Japanese disaster relief in March 2011.

Last but not least, I would like to thank you for reading this book. Your belief in my work is what keeps me writing more books that help readers be more productive and creative.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.79.121