Thread
- A thread is also called a Lightweight Process.
- Each thread belongs to exactly one process and no thread can exist outside a process.
- But, one process can contain multiple threads.
- Each thread represents a separate flow of control, thread is a path of execution within a process.
- A thread is a flow of execution through the process code, with its program counter that keeps track of which instruction to execute next, system registers that hold its current working variables, and a stack that contains the execution history.
- Threads are generally used to improve the application through Parallelism.
- In the operating system, there are two types of threads:
- Kernel-level Thread
- User-level Thread
- Advantages of a thread depending on the type of thread.
Let's see the advantages of threads according to their types.
Advantages of Kernel-level Thread:
- Multiple threads of the same process can be scheduled on different processors.
- The routines of the kernel can also be multithreaded.
- If a kernel-level thread is blocked, another thread of the same process can be scheduled by the kernel.
- These threads are fully aware of all other threads.
- Hence, Scheduler may decide to give more time to a process having a large number of threads than a process having a small number of threads.
-These threads are good for applications that frequently block.
Advantages of User-level Thread:
- Implementing threads at user space is easier and faster to create than threads at the kernel level.
- They can also be more easily managed.
- These threads can be run on any operating system.
- It does not need any support from the kernel-level threads.
- The overall process is quick and effective because there is no requirement for a system call.
- No need for the kernel-mode privileges for the thread to switch in userspace.
- The organization is straightforward because the threads are produced, switched, and controlled without interference from the kernel.
- Do not require modification to operating systems.