BIT204 ยท 2078 ยท 5 marks
What is thread? Explain user level thread and kernel level thread.
What is thread? Explain user level thread and kernel level thread. [5]
Quick answer
A thread is the smallest unit of CPU execution within a process. It is also called a lightweight process (LWP).
Thread, User Level Thread, and Kernel Level Thread
What is a Thread?
A thread is the smallest unit of CPU execution within a process. It is also called a lightweight process (LWP). A thread shares the code section, data section, and OS resources (like open files and signals) with other threads belonging to the same process, but has its own:
- Thread ID
- Program counter (PC)
- Register set
- Stack
A process can have multiple threads running concurrently, which improves performance and responsiveness.
User Level Threads (ULT)
User level threads are managed entirely by a user-space thread library (e.g., POSIX Pthreads) without kernel involvement.
Characteristics:
- The kernel is not aware of the existence of these threads.
- Thread management (creation, scheduling, synchronization) is done by the user-level library.
- From the kernel's perspective, the entire process appears as a single-threaded process.
Advantages:
- Thread switching does not require kernel mode, so it is faster.
- Can be implemented on any OS, even those that do not support threads.
- More portable and flexible scheduling.
Disadvantages:
- If one thread makes a blocking system call, the entire process is blocked.
- Cannot take advantage of multiprocessor systems (all threads map to one kernel thread).
Kernel Level Threads (KLT)
Kernel level threads are managed directly by the operating system kernel.
Characteristics:
- The kernel maintains information about each thread.
- Thread creation, scheduling, and management are performed by the kernel.
- Each user thread maps to a kernel thread.
Advantages:
- If one thread is blocked, the kernel can schedule another thread of the same process.
- Can run on multiple processors simultaneously (true parallelism).
- Better support for multiprocessor environments.
Disadvantages:
- Thread switching requires a mode switch to kernel, making it slower than ULT.
- More overhead in thread management.
Comparison Table
| Feature | User Level Thread | Kernel Level Thread |
|---|---|---|
| Managed by | User-space library | Operating System Kernel |
| Kernel awareness | Not aware | Fully aware |
| Speed | Faster (no mode switch) | Slower (mode switch needed) |
| Blocking | Blocks entire process | Only the calling thread blocks |
| Multiprocessor support | No | Yes |
| Example | POSIX Pthreads (user mode) | Windows threads, Linux threads |
Note: Many modern operating systems use a combined (hybrid) approach where multiple user threads are mapped to multiple kernel threads to get the benefits of both models.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.