Since you will normally have only one processor, but expect several tasks to run at the same time, OS/2 switches between tasks several dozen times a second. As a result, these programs appear to run in parallel. This is called multitasking.

But even if you have a multi-processor (SMP) system, there will always be more tasks than processors on your system, so switching is still required.

A thread is OS/2's unit for administrating task switches. A program can contain several threads, but per definition, it will have at least one. But since a program can have more than one thread, switching can take place even between threads in the same program. This is called multithreading. As opposed to many other operating systems, OS/2 fully supports this, and it even does so in a very fancy and reliable way.

The part of the OS/2 kernel which switches between threads is called the "scheduler".

The term "thread" was chosen because within one thread program instructions are executed sequentially, while between threads you may never be sure which instruction of one thread will be executed before or after an instruction of another thread. It is only OS/2 which keeps switching between threads without the thread even knowing about it (or, on SMP systems, threads might actually run concurrently on several processors).

Well-programmed OS/2 software uses several threads to ensure that the user gets a quick response to his input and mouse actions. For example, if you execute a command in a program which will take a long time, a program should start a secondary thread for this task. While this new thread is working in the background, the user interface (on the main thread of the program) is ready again for new input.

Not-so-well-programmed OS/2 software uses only one thread for both the user interface and executing tasks. As a result, while executing a task, the user interface is blocked.

Threads can have different priorities. In general, a thread with a higher priority gets more processor time that one with lower priority. To be more precise, OS/2 looks at thread priorities if more than one thread is internally marked as "ready". By contrast, threads which are currently "blocked" need no CPU time anyway, so for them, priorities do not matter until they are unblocked again. Note that on your typical OS/2 system, the large majority of threads will be in "blocked" state at any given point in time.

OS/2 is capable of controlling thread priorities in a very refined way. It differentiates between four priority classes:

  1. "Idle time priority" is the lowest priority class. This means that a thread only gets processor time if no threads of higher priority classes are running. Such threads are helpful for offloading work that needs to be done, but can be delayed until the computer has time for it. An example of such a thread is &xwp;'s own Worker thread, which keeps track of the awake WPS objects on your system. This is fairly time-consuming, but not time-critical, so it's done with idle-time priority.

  2. "Regular priority" is the priority class that most threads use. It is also the default OS/2 priority class if a thread does not explicitly change its priority. Between threads of this class, OS/2 dynamically varies priority levels (more on this below) to make sure that no thread of this class "starves", i.e. gets no processor time.

  3. "Time-critical priority" is the second-highest priority class for threads that do not want to be influenced by the dynamic priority variations for "regular" threads. This is sometimes used for message dispatchers and multimedia threads which do not take a lot of time but need more attention.

  4. "Foreground server priority" is the highest priority class for threads that need to be executed immediately when there's work to do. Such a thread will be given processor time immediately and will not be interrupted until its work is done. This priority class is normally only used for network and other communications software, or CD writers, or MP3 players.
Within each priority class, a thread may set a priority level. This is a value from 0 to +31 which determines the precedence of a thread within a priority class and will only be taken into account if two threads of the same priority class compete.

A few examples:

On the other hand side, a process is the OS/2 term for an application which has been loaded into memory. Each process must have at least one thread.

Each process contains common data as well as controls access to system resources. Processes are protected against each other in that OS/2 prohibits access to memory which does not belong to the process attempting to access it ("memory protection").

By contrast, several threads within a process may all access the process's memory, because memory is administered on a per-process basis. The same applies to other system resources such as open files.

To summarize, threads own only the CPU until they are interrupted by OS/2 (over which they have little control, other than setting their priorities). By contrast, processes own everything else: files, devices, and memory.