What Is A Thread?
A thread is a lightweight process that can be managed independently by a scheduler. It improves the application performance through parallelism. Thread shares information like code segment, open files and data segment with other peer threads. Threads have their own system registers which hold its current working variables, a stack which contains the execution history and counter that keeps track of which instruction to execute next.
Threads represent a software approach to improving performance of operating system by reducing overhead. Thread is equivalent to a classical process. There are two main types of threads, they include:
- User Level Thread (User managed threads)
- Kernel Level Thread (Operating System managed threads acting on Kernel, an operating system core).
User Level Thread
User-level threads are small and much faster than kernel level threads. They are directly supported by the operating system. User-level threads are implemented by users and the kernel is not aware of the existence of these threads. It handles these threads as if they were single-threaded processes. The application area of user-level thread does not have thread management code.
User level thread is also called many-to-one mapping thread because the operating system maps all threads in a multithreaded process to a single execution context. The operating system considers each multithreaded processes as a single execution unit.
Also Read: Difference Between Segmentation And Paging In OS
What You Need To Know About User Level Thread
- Support provided at the user level is referred to as user level thread.
- User level thread is also called many-to-one mapping thread because the operating system maps all threads in a multithreaded process to a single execution context. The operating system considers each multithreaded processes as a single execution unit.
- User level thread uses space for thread scheduling. The threads are transparent to the operating system.
- User level threads do not invoke the kernel for scheduling decision.
- User threads are implemented by users and managed entirely by the run-time system.
- Implementation of user threads is easy.
- If one user level thread performs blocking operation then entire process will be blocked.
- User level can run on any operating system.
- Context switch time is less.
- Context Switch requires Hardware Support
- Context switch requires no hardware support.
- Multithread application cannot take advantage of multiprocessing.
- User level threads are created by runtime libraries that cannot execute privileged instructions.
- User level threads have low overhead but, can achieve high-performance in computation.
- The code for creating and destroying the thread, message passing, data transfer and thread scheduling is included into thread library.
- Example of user-thread libraries include: POSIX Pthreads, Mach C-threads, and Solaris 2 UI-threads.
Kernel Level Thread
Kernel-level threads are handled by the operating system directly and the thread management is done by the kernel. In thread-level thread, there is no thread management code in the application area and multiple threads of the same process can be scheduled on different processors in kernel-level threads.
Since kernel managing threads, kernel can schedule another thread if a given thread blocks rather than blocking the entire processes. Kernel threads are typically slower to create and manage than the user threads; and transfer of control from one thread to another within the same process requires a mode switch to the kernel.
Also Read: Difference Between Process And Thread In OS
What You Need To Know About Kernel Level Thread
- Support provided by kernel is referred to as Kernel level thread.
- Threads are constructed and controlled by system calls. The system knows the state of each thread.
- Kernel level thread support one-to-one thread mapping. Mapping requires each user thread with kernel thread. Operating system performs this mapping.
- Kernel level threads are implemented by Operating system. In the kernel level thread, thread management is done by kernel.
- Implementation of kernel thread is complicated.
- Since kernel managing threads, kernel can schedule another thread if a given thread blocks rather than blocking the entire processes.
- Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process.
- Kernel level thread support one to one thread mapping.
- Kernel level threads are specific to the operating system.
- Context switch time is more.
- Kernel performs scheduling on a thread basis. The kernel support and management thread creation only in Kernel space.
- Hardware support is needed.
- Kernel routines themselves can be multithreaded.
- Kernel level threads are slower than user level threads.
- Thread management code is not included in the application code. It is the only API to the kernel thread. Windows operating system uses this facility.
- Example of kernel level thread include: Windows NT, Windows 2000, Solaris 2, BeOS and Tru64 UNIX (formerly digital UNIX)
Also Read: Difference Between Physical And Logical Address In Operating System
Difference Between User Level Thread And Kernel Level Thread In Tabular Form
BASIS OF COMPARISON | USER LEVEL THREAD | KERNEL LEVEL THREAD |
Description | Support provided at the user level is referred to as user level thread. | Support provided by kernel is referred to as Kernel level thread. |
Thread Mapping | User level thread is also called many-to-one mapping thread because the operating system maps all threads in a multithreaded process to a single execution context. The operating system considers each multithreaded processes as a single execution unit. | Kernel level thread support one-to-one thread mapping. Mapping requires each user thread with kernel thread. Operating system performs this mapping. |
Examples | Example of user-thread libraries include: POSIX Pthreads, Mach C-threads, and Solaris 2 UI-threads. | Example of kernel level thread include: Windows NT, Windows 2000, Solaris 2, BeOS and Tru64 UNIX (formerly digital UNIX) |
Context Switch Time | Context switch time is less. | Context switch time is more. |
Speed | User level threads are faster than kernel level thread. | Kernel level threads are slower than user level threads. |
Multithreading | Multithread application cannot take advantage of multiprocessing. | Kernel routines themselves can be multithreaded. |
Hardware Support | Context Switch requires Hardware Support | Hardware support is needed. |
Implementation | Implementation of user threads is easy. | Implementation of kernel thread is complicated. |
Operating System | User level can run on any operating system. | Kernel level threads are specific to the operating system. |
Application Code | The code for creating and destroying the thread, message passing, data transfer and thread scheduling is included into thread library. | Thread management code is not included in the application code. It is the only API to the kernel thread. Windows operating system uses this facility. |
System Calls | User level threads do not invoke the kernel for scheduling decision. | Threads are constructed and controlled by system calls. The system knows the state of each thread. |
Operation Space | User level thread uses space for thread scheduling. The threads are transparent to the operating system. | Kernel performs scheduling on a thread basis. The kernel support and management thread creation only happens in Kernel space. |