Kernel level threads
- Threads of processes defined by operating system itself are called kernel threads.
- In these types of threads, kernel performs thread creation, scheduling and management in kernel space.
- Kernel threads are used for internal workings of the operating system, such as scheduling the user threads.
- Kernel threads are slower to create and manage as operating system manages them.
- If a thread performs a blocking system call, the kernel can schedule another threads in the application for execution.
- In multiprocessor environment, the kernel can schedule threads on different processors.
- The various operating systems that support kernel level threads are windows NT, Windows 2000, Solaris 2.
Advantages of kernel level threads
- The operating system can schedule multiple threads for the same process on multiple processors.
- The operating system is aware of the presence of threads in the processes, therefore, even if one thread of a process gets blocked, the operating system chooses the next one to run either from the same process or from the different process. Hence they are good for applications that frequently block.
- Kernel routines themselves can be multithreaded.
Disadvantages of kernel level threads
- Kernel level threads are slower and inefficient.
- Switching between threads is time consuming as the kernel performs switching (via an interrupt).
- Since kernel must manage and schedule threads as processes, it requires full threads control block (TCB) for each thread. As a result there is significant overhead and increase in kernel complexity.
User level threads
- The threads of user application process are called user threads.
- They are implemented entirely in the user space of the main memory.
- They are supported above the kernel and are implemented in user level libraries rather than via a system call.
- Here, user level library (containing functions to manipulate user threads) is used for thread creation, scheduling and management without any support from kernel.
- As kernel’s intervention is not required in thread creation and scheduling, user level threads are fast to create and manage.
Advantages of user level threads
- User level threads are fast in creation as kernel intervention is not required.
- There is fast switching among threads, as switching between user level threads can be done independent of the operating system.
- They have better performance over kernel threads as they do not need to make system calls for threads creation.
- Threads scheduling can be application specific.
- User level threads can run on any operating system.
Disadvantages of user level threads
- When a user level thread executes a system call, not only that thread is blocked but also all of the threads within the process are blocked. This is because operating system is unaware of the presence of threads and only knows about the existence of a process actually constituting these threads.
- Multithreaded applications using user level threads cannot take the advantage of multiprocessing as kernel assigns one process to only one processor as a time. This is again because of operating system is unaware of the presence of threads and schedules processes not threads.
Difference between Kernel level thread and User level thread
|S. No.||Kernel level thread||User level thread|
|1.||Threads of processes defined by operating system itself are called kernel threads.||The threads of user application process are called user threads.|
|2.||Kernel performs thread creation, scheduling and management in kernel space||They are implemented entirely in the user space of the main memory|
|3.||Kernel threads are slower to create and manage as operating system manages them.||User level threads are fast to create and manage as kernel’s intervention is not required in thread creation scheduling|