Multithreaded Programming Guide

Lightweight Processes

The threads library uses underlying threads of control called lightweight processes that are supported by the kernel. You can think of an LWP as a virtual CPU that executes code or system calls.

You usually do not need to concern yourself with LWPs to program with threads. The information here about LWPs is provided as background, so you can understand the differences in scheduling scope, described on "Process Scope (Unbound Threads)".

Note -

The LWPs in the Solaris 2, Solaris 7, and Solaris 8 operating environments are not the same as the LWPs in the SunOSTM 4.0 LWP library, which are not supported in the Solaris 2, Solaris 7, and Solaris 8 operating environments.

Much as the stdio library routines such as fopen() and fread() use the open() and read() functions, the threads interface uses the LWP interface, and for many of the same reasons.

Lightweight processes (LWPs) bridge the user level and the kernel level. Each process contains one or more LWP, each of which runs one or more user threads. (See Figure 1-1.) The creation of a thread usually involves just the creation of some user context, but not the creation of an LWP.

Figure 1-1 User-level Threads and Lightweight Processes


Each LWP is a kernel resource in a kernel pool, and is allocated (attached) and de-allocated (detached) to a thread on a per thread basis. This happens as threads are scheduled or created and destroyed.