1. Introduction: What is a thread and what is it good for?

Threads are often called lightweight processes and while this term is somewhat of an over simplification, it is a good starting point. Threads are cousins to UNIX processes though they are not processes themselves. To understand the distinction we must examine the relation between UNIX processes and Mach tasks and threads. In UNIX, a process contains both an executing program and a bundle of resources such as the file descriptor table and address space. In Mach, a task contains only a bundle of resources; threads handle all execution activities. A Mach task may have any number of threads associated with it and all threads must be associated with some task. All threads associated with a given task share the task's resources. Thus a thread is essentially a program counter, a stack, and a set of registers -- all the other data structures belong to the task. A UNIX process in Mach is modeled as a task with a single thread.

Since threads are very small compared with processes, thread creation is relatively cheap in terms of CPU costs. As processes require their own resource bundle, and threads share resources, threads are likewise memory frugal. Mach threads give programmers the ability to write concurrent applications that run on both uniprocessor and multiprocessor machines transparently, taking advantage of the additional processors when they exist. Additionally, threads can increase performance in a uniprocessor environment when the application performs operations that are likely to block or cause delays, such file or socket I/O.

In the following sections we discuss portions of the POSIX threads standard and its specific implementation in the DEC OSF/1 OS, V3.0. POSIX threads are called pthreads and are similar to the non-POSIX cthreads.


Move to: Contents or Next Section