Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: newbie question: What is a Blue Task
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: newbie question: What is a Blue Task

pete wrote:

> Recently I joined this list and I noticed people are talking about Blue Task on Mac OS 8/9... just exactly what is a Blue Task?

Short answer: It is described in the Multitasking docs in the Apple developer section.

Long answer: Starting with Mac OS 8.6, the system has a preemptive multitasking nanokernel which schedules tasks preemptively. One
special task is used to run the entirety of the cooperative tasking system, and that is called the blue task. The docs call this
task the "Mac OS" task, which is a bit confusing but avoids using an old code word.

Think of the blue task as harboring all your standard apps. This is where the higher level process manager lives. It performs the
cooperative tasking, and actually 'it' is merely a bunch of subroutines that get entered when your standard app calls
WaitNextEvent, EventAvail, etc.

What is important to note is the blue task is just another task preemptively scheduled by the nanokernel. An application running
compute bound will not stop other tasks from getting time. Conversely any other preemptive tasks (aka MP tasks) will not stop the
blue task from getting time.

Answering a few other questions poses to this list, people have asked in various ways: "Why is there a lot of juju involved to
keep MPtasks going?"

The problem arises when MPtasks must communicate with functions that for compatibility reasons must run in the cooperative
environment: file I/O, large block memory allocations, GUI calls, page fault resolution in systems prior to 9.1. In this case a
function in an MP task communicates to the blue task by way of MPRemoteCall. In a sense the blue task is treated as a general
server, but it isn't a great server for an important compatibility reason: cooperative tasking.

Some calls can be made directly because they are inherently MP-safe. Other calls can be executed at interrupt level (which is just
a special instance of the blue task), and so these requests can be serviced fast. File I/O, for example, when called from an MP
task takes around 2-10 microseconds to get the request serviced in the blue task. Other requests have to occur at app time. There
is code in the process manager to service pending requests when entering/exiting the cooperative app.

If all apps are well behaved, meaning they do not run for an excessive amount of time between WaitNextEvent, EventAvail, etc.
calls, then the serviced requests suffer minimal latencies as low as 100 microseconds. If *any* app is ill behaved then all
requests are delayed by the amount of time that app commandeered.

The ideal app is one that acts as a server for its spawned MP tasks. The cooperative side of the app handles the GUI interactions
and services requests coming in from the MP tasks. Such an app would scale well with multiple processors and on all systems would
prevent the host of headaches causes by a cooperative side going compute bound which then locks up menus, or other apps from
responding quickly.

Obviously this preemptive/cooperative bridge is a large wart in the overall design of the system. Combining preemptive
multitasking with cooperative tasking and doing so with high compatibility with existing apps on OS 9 is difficult. We probably
could make this better given time but our mandate is OS X.


 >newbie question: What is a Blue Task (From: pete <email@hidden>)

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.