Chapter 5. Cooperative Single-Tasking
Lots of veteran Mac programmers like to joke about the trials and tribulations of cooperative multitasking as it existed on the Mac OS prior to OS X. For those unfamiliar with the concept, cooperative multitasking is a sort of time-sharing pattern for computer processes. In a cooperative multitasking system, a selected process will take focus and use the majority of available resources to perform its work. After a time, that process should yield control of those resources to other, waiting processes. In this model, however, it’s not uncommon for a bug in one application to “freeze” the entire operating system by blocking access to the CPU. This was a common enough problem in pre-OS X days that the power button on older Macs often had as much wear and tear as the space bar on the keyboard.
The iPhone OS leverages an operating system that, at its core, handles multitasking very well. Unfortunately, Apple has given developers of iPhone applications a set of rules that prevent access to true multitasking. We know that, for all intents and purposes, custom Cocoa Touch applications are not allowed to run in the background. This means that when an application isn’t in focus and doesn’t have full control of the screen, code from that application cannot run.
There are obvious exceptions to this rule. For example, the Phone, iPod, Mail, SMS, and Alarm applications take advantage of background processes to perform their functions. Unless a special relationship ...