A thread is a part of a process. A process is classified into a number of light-weighted processes, each light weighted process is known as a thread. It is a track of execution in process. The thread has a program counter that holds the path of which instruction to execute next.
It has a register which keep the current working variable and a stack which store the execution history. For example, when we open a site, then after scrolling down some ads came automatically (which is a thread), some random videos played (which is another thread). Here, opening a site is a process but ads coming and playing videos are threads.
- There are two types of threads
- Difference between user-level thread and kernel-level thread
- Advantages and Disadvantage of User level thread
- Advantages and Disadvantage of Kernel level thread
There are two types of threads
- User level thread
- Kernel level thread
Difference between user-level thread and kernel-level thread
|User level thread||Kernel level thread|
|These threads are handled by a user-level library.||These threads are handled by operating systems i.e., system calls.|
|User-level threads are typically faster than kernel-level thread.||Kernel-level threads are slower than user-level threads.|
|In this thread, context switching is fast.||In kernel-level thread, context switching is slow.|
|In user level threads, if one thread functions blocking operation then whole process gets blocked.||In kernel level thread, when one thread is blocked then no effect on other kernel level threads.|
Advantages and Disadvantage of User level thread
Advantages of User level thread
- These threads are faster and simpler to create and can handled easily.
- It can be run on any operating system.
Disadvantages of User level thread
- In user level thread, if one thread function blocking operation then whole process get blocked.
- In user level thread, multithreaded applications cannot usage multiprocessing.
Advantages and Disadvantage of Kernel level thread
Advantages of Kernel level thread
- In kernel level thread, when one thread is blocked then no any effect on other kernel level threads.
- The kernel regulations can be multithreaded.
Disadvantages of kernel level thread
- Kernel level threads are slower to handle and create.
- To transmit control from one thread to another thread in a process, a mode switch to kernel mode is needed.