display | more...
Also known as a thread, a lightweight process (c.v. heavyweight process) can be thought of as the basic unit of CPU usage. If you have ever seen a tract of geek-speak mentioning multi-threaded applications, they're talking about LWPs.

A lightweight process contains a unique ID, a program counter, a register set and a stack. Lightweight processes are special in that they share their code space, data section, and OpSys resources like files accessed and possibly messages. LWPs allow a computer to do many things at once.

For example, a web server receives many many requests for data. Without lightweight processes, it would have to answer those requests one at a time, which would create lag the size of which your mind cannot safely conceive. Instead, the server spins off a LWP and schedules it through the CPU in some OpSys-dependent sequence with all the other little LWPs, reducing the lag to a more manageable level. Lightweight processes are also generally easier to create than a full process, since the CPU does not have to allocate all of the resources that would normally required.

     Single-thread            Multi-threaded
     Architecture             Architecture
,---------------------.  ,---------------------.
| Code | Data | Files |  | Code | Data | Files |
|------+------+-------|  `>-------------------<`
| Regs |      | Stack |  | Regs | Regs | Regs  |
|---------------------|  |------+------+-------|
|                     |  | Stack| Stack| Stack |
|      Process        |  |------+------+-------|
|                     |  |      |      |       |
`---------------------`  | LWP1 | LWP2 | LWP3  |
                         |      |      |       |
                         `---------------------`
In some operating systems, a fixed number of LWPs are created during start up. These threads will be assigned tasks throughout the time that the system is left running. This saves time, since the OpSys never has to spin off a new lightweight process, and the number of LWPs in existence will never grow beyond the handling capability of the OpSys that spawned them.


LWP diagram adapted from Operating System Concepts, 6th Edition by Silberschatz, Galvin and Gagne.

Log in or register to write something here or to contact authors.