Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Lightweight process (LWP)
Many systems implement either the many-to-many or the two-level model by placing an intermediate data structure between user and kernel threads. This data structure is typically known as a Lightweight Process (LWP) and serves as a virtual processor for scheduling user threads.
How Lightweight Processes Work
To the user-thread library, the LWP appears to be a virtual processor on which the application can schedule a user thread to run. Each LWP is attached to a kernel thread, and it is the kernel threads that the operating system schedules to run on physical processors.
Key Characteristics
Virtual Processor − LWPs appear as virtual processors to the user-thread library
One-to-One Mapping − Each LWP is attached to exactly one kernel thread
Blocking Behavior − If a kernel thread blocks (such as during I/O operations), the LWP blocks, and any user thread attached to that LWP also blocks
OS Scheduling − The operating system schedules kernel threads (not LWPs directly) to run on physical processors
Determining the Number of LWPs
The optimal number of LWPs depends on the application's characteristics:
| Application Type | LWPs Required | Reason |
|---|---|---|
| CPU-bound (single processor) | 1 | Only one thread can run at a time |
| I/O-intensive | Multiple | Handle concurrent blocking system calls |
| Mixed workload | Variable | Based on concurrency requirements |
Example − I/O-Intensive Application
Consider an application that performs four simultaneous file-read requests. Four LWPs are needed because all could be waiting for I/O completion in the kernel simultaneously. If the process has only three LWPs, the fourth request must wait for one of the existing LWPs to return from the kernel before it can proceed.
Advantages and Disadvantages
| Advantages | Disadvantages |
|---|---|
| Provides flexibility in thread scheduling | Additional overhead compared to pure user threads |
| Enables concurrent I/O operations | Requires careful tuning of LWP count |
| Better resource utilization | More complex than one-to-one mapping |
| Supports both CPU and I/O bound tasks | Can lead to resource contention |
Conclusion
Lightweight Processes serve as an intermediate layer between user threads and kernel threads, providing virtual processors for thread scheduling. The number of LWPs required depends on the application's concurrency needs, with I/O-intensive applications typically requiring more LWPs to handle simultaneous blocking operations efficiently.
