Types of Threading in Operating System



In operating system, threads are single sequence stream within a process also known as lightweight processes. Threads are used to achieve parallelism by dividing a process into multiple threads of independent path of execution while sharing the same common memory, space, and resource. For example: tabs of a web browser.

An operating System is divided into two spaces: User Space and Kernel Space. Based on these two spaces, threads can be classified into two types as shown in the image below −

Thread Types

Types of Threads

There are two types of threads that are mentioned below −

User Level Threads

ULTs or User-level threads are implemented in user space by thread libraries. In this, the kernel is not aware of ULTs. Kernel manages them just like a single threaded processes. In this space, operations like thread creation, scheduling, synchronization is done.

User-level threads are small and much faster than kernel level threads. They are represented by a program counter(PC), stack, registers and a small process control block. Also, there is no kernel involvement in synchronization for user-level threads. Examples of user-level thread: POSIX Pthreads, Java green threads, GNU Portable Threads (GNU Pth), etc.

Advantages of User Level Thread

The advantages of user-level threads are as follows −

  • User level threads are easier and faster to create and manage than kernel-level threads.
  • Faster thread switching as there is no involvement of Kernel.
  • User level thread can run on any operating system.
  • Scheduling can be application specific in the user level thread.

Disadvantages of User Level Thread

The disadvantages of user-level threads are given below −

  • Multithreaded applications in user-level threads cannot use multiprocessing to their advantage.
  • If one user-level thread performs blocking operation then the entire process is blocked.

Kernel Level Threads

The kernel directly manages KLTs(Kernel-level threads) and supported directly by the operating system. Any application can be programmed to be multithreaded. All of the threads within an application are supported within a single process. The kernel maintains thread information and also performs operations like thread creation, scheduling, and management. In this space, the kernel is aware of all threads in the system unlike ULTs.

The context information for the process as well as the process threads is all managed by the kernel. The thread Scheduling by the Kernel is done on a thread basis. Because of this, kernel-level threads are slower than user-level threads. Examples of kernel-level thread: Windows threads, Linux threads, Solaris threads, Video games, etc.

Advantages of Kernel Level Thread

The advantages of kernel level threads are mentioned below −

  • Kernel can simultaneously schedule multiple threads from the same process on multiple processes.
  • If one thread in a process is blocked, the Kernel can schedule another thread of the same process.
  • Kernel routines themselves can be multithreaded.

Disadvantages of kernel Level Thread

The disadvantages of kernel level threads are given below −

  • Kernel threads are generally slower to create and manage than the user threads.
  • Transfer of control from one thread to another within the same process requires a mode switch to the Kernel.

Difference Between User Level and Kernel Level Thread

The differences between user level and kernel level threads are given below −

User Level Thread Kernel Level Thread
It is lightweight and simple to implement. It is heavyweight and more complex to implement than user level thread.
User level threads are managed without kernel support. Kernel level threads are managed and supported directly by the operating system.
Kernel is not aware of user threads. Kernel is fully aware and manages threads.
User level threads are faster to create and manage. Kernel level threads are slower to create and manage.
User level threads cannot take advantage of multiprocessing. Kernel level threads can take advantage of multiprocessing.
If one user level thread performs blocking operation, the entire process is blocked. If one kernel level thread performs blocking operation, other threads in the same process can continue to execute.
There is low overhead in this. High overhead because of system calls
Thread scheduling is done using thread library(user-level scheduler). Thread scheduling is done by OS kernel scheduler
There is no need of system calls for thread operations It needs system calls for thread operations
It is better for thread switching. It is better for blocking operations.

Conclusion

In operating systems, threads are of two types: User Level Threads (ULTs) and Kernel Level Threads (KLTs). User Level Threads (ULTs) are lightweight, faster to create, and are managed in user space but they are not good for multiprocessing and the entire process gets blocked if one thread is blocked. Kernel Level Threads (KLTs) are managed by the kernel, and is suitable for multiprocessing and can independently execute threads in the same process. KLTs are complex and slower compared to ULTs.

Advertisements