Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Macintosh Toolbox Essentials /
Chapter 2 - Event Manager / Introduction to Events


Switching Contexts

Processes running in the background receive processing time when the foreground process makes an event call (that is, calls WaitNextEvent or EventAvail) and there are no events pending for that foreground process. A process running in the background should relinquish the CPU regularly to ensure a timely return to the foreground process when necessary.

In System 7 (or with MultiFinder in earlier versions), the available processing time is distributed among multiple processes through a procedure known as context switching (or just switching). All switching occurs at a well-defined time, namely, when an application calls WaitNextEvent. When a context switch occurs, the Process Manager allocates processing time to a process other than the one that had been receiving processing time. Two types of context switching may occur: major and minor.

A major switch is a complete context switch: an application's windows are moved from the back to the front, or vice versa. In a major switch, two applications are involved, the one being switched to the foreground and the one being switched to the background. The Process Manager switches the A5 worlds of both applications, as well as the relevant low-memory environments. If those applications receive suspend and resume events, they are so notified at the time that a major switch occurs.

A minor switch occurs when the Process Manager gives time to a background process without bringing the background process to the front. The two processes involved in a minor switch can be two background processes or a foreground process and a background process. As in a major switch, the Process Manager switches the A5 worlds and the low-memory environments of the two processes. However, the order of windows is not switched, and neither process receives either suspend or resume events.

When the frontmost window is an alert box or a modal dialog box, major switching does not occur, although minor switching can. To determine whether major switching can occur, the Operating System checks (among other things) to see if the window definition procedure of the frontmost window is dBoxProc, because the type dBoxProc is specifically reserved for alert boxes and modal dialog boxes. (If the frontmost window is a movable modal dialog box, major switching can still occur.)

Note
Your application can also get switched out if it calls a system software routine that makes an event call. For example, when your application calls ModalDialog, a minor switch can occur. u
Your application can receive processing time and perform tasks in the background,
but your application should not interact with the user or perform tasks that would slow down the responsiveness of the foreground process.

Your application indicates scheduling options to the Operating System, such as whether the application can use null-event processing time when in the background, whether it can accept suspend and resume events, and so forth, by setting flags in its size ('SIZE') resource. Every application executing in System 7, as well as every application executing in System 6 with MultiFinder, should contain a 'SIZE' resource. See "Creating a Size Resource" beginning on page 2-30 for details on how to specify this information.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 JUL 1996