A thread is a basic unit of CPU utilization. It is also called a lightweight process. CPU threads share the code section, data section, and any operating system resources with its peer threads in a particular task which are vacant for the job.
In this article, you will be able to learn about a thread, different types of threads, their advantages and disadvantages, major differences between process and threads, etc. Let’s read it further.
Have You Read About:
CPU Threads
A thread is a basic unit of CPU utilization. It is also called a lightweight process. It is a sequence of instructions within a process. A CPU thread behaves like a process within a process but it does not have its own PCB.
Usually, multiple threads are created within a process. The multiple CPU threads in a process allow multiple executions. It can be used to improve the application through parallelism. Threads consist of the following:
- Thread ID
- Program Counter
- Register Set
- Stack
A thread shares the following with its peer threads in a particular task: Thread is a sequence of instructions within a process. It behaves like a process within a process but it does not have its own PCB. Types:Kernel-Level & User-Level
- Code Section
- Data Section
- Any operating system resources, which are vacant for the job.
Benefits of CPU Threads
Some important benefits of threads are as follows:
- Threads share common data and do not require to make use of inter-process communication.
- Threads can get an advantage of multiprocessors
- There is a higher throughput when multiple threads collaborate in a single job. The entire process does not stop if one thread must wait.
- Threads are cheap to create as they only need a stack and storage to register
- Threads use very few resources of an operating system. They do not need new address space, global data, program code, or operating system resources
- Context switching becomes fast when working with threads.
Difference B/w Process And Thread
The difference between processes and threads are as follows:
Thread |
Process |
A thread is a lightweight entity |
A process is a heavyweight entity |
A thread cannot exist without a process |
There must be at least one thread in a process |
If a thread ends, the process may still run. |
If a process ends, all threads in it also end |
A thread has no data segment or heap |
A process has code, data, and heap segments |
The communication among threads occurs via memory |
The communication among processes occurs via the operating system and data copying |
The creation of threads and context switching is inexpensive |
The creation of processes and context switching is expensive. |
Types of CPU Threads
Threads may be handled at different levels. There are two types of CPU threads to manage in a modern system. One is called the user thread and 2nd is the kernel thread.
Kernel-level threads are supported within the kernel of the operating system. All modern operating systems support kernel-level threads. They allow the kernel to perform multiple tasks and to service multiple kernel system calls simultaneously.