Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Advantages of Thread over Process

1. Responsiveness: If the process is divided into multiple threads, if one thread


completes its execution, then its output can be immediately returned.
2. Faster context switch:  Context switch time between threads is lower compared to
process context switch. Process context switching requires more overhead from the
CPU.
3. Effective utilization of multiprocessor system: If we have multiple threads in a single
process, then we can schedule multiple threads on multiple processor. This will make
process execution faster.
4. Resource sharing: Resources like code, data, and files can be shared among all
threads within a process.
Note: stack and registers can’t be shared among the threads. Each thread has its own
stack and registers.
5. Communication:  Communication between multiple threads is easier, as the threads
shares common address space. while in process we have to follow some specific
communication technique for communication between two process.
6. Enhanced throughput of the system: If a process is divided into multiple threads, and
each thread function is considered as one job, then the number of jobs completed per
unit of time is increased, thus increasing the throughput of the system.

1. User Level thread (ULT) –


Is implemented in the user level library, they are not created using the system
calls. Thread switching does not need to call OS and to cause interrupt to
Kernel. Kernel doesn’t know about the user level thread and manages them as
if they were single-threaded processes.
Advantages of ULT –
 Can be implemented on an OS that does’t support multithreading.
 Simple representation since thread has only program counter,
register set, stack space.
 Simple to create since no intervention of kernel.
 Thread switching is fast since no OS calls need to be made.
Disadvantages of ULT –
 No or less co-ordination among the threads and Kernel.
 If one thread causes a page fault, the entire process blocks.
2. Kernel Level Thread (KLT) –
Kernel knows and manages the threads. Instead of thread table in each
process, the kernel itself has thread table (a master one) that keeps track of all
the threads in the system. In addition kernel also maintains the traditional
process table to keep track of the processes. OS kernel provides system call to
create and manage threads.
Advantages of KLT –
 Since kernel has full knowledge about the threads in the system,
scheduler may decide to give more time to processes having large
number of threads.
 Good for applications that frequently block.
Disadvantages of KLT –
 Slow and inefficient.
 It requires thread control block so it is an overhead.
Summary:
1. Each ULT has a process that keeps track of the thread using the Thread table.
2. Each KLT has Thread Table (TCB) as well as the Process Table (PCB).

Multithreading in Operating System


A thread is a path which is followed during a program’s execution. Majority of
programs written now a days run as a single thread.Lets say, for example a program is
not capable of reading keystrokes while making drawings. These tasks cannot be
executed by the program at the same time. This problem can be solved through
multitasking so that two or more tasks can be executed simultaneously.
Multitasking is of two types: Processor based and thread based. Processor based
multitasking is totally managed by the OS, however multitasking through
multithreading can be controlled by the programmer to some extent.
The concept of multi-threading needs proper understanding of these two terms – a
process and a thread. A process is a program being executed. A process can be further
divided into independent units known as threads.
A thread is like a small light-weight process within a process. Or we can say a
collection of threads is what is known as a process.

Applications –
Threading is used widely in almost every field. Most widely it is seen over the internet
now days where we are using transaction processing of every type like recharges, online
transfer, banking etc. Threading is a segment which divide the code into small parts that
are of very light weight and has less burden on CPU memory so that it can be easily
worked out and can achieve goal in desired field. The concept of threading is designed
due to the problem of fast and regular changes in technology and less the work in
different areas due to less application. Then as says “need is the generation of creation
or innovation” hence by following this approach human mind develop the concept of
thread to enhance the capability of programming.

The benefits of multi threaded programming can be broken down into four major
categories:
1. Responsiveness –
Multithreading in an interactive application may allow a program to continue
running even if a part of it is blocked or is performing a lengthy operation,
thereby increasing responsiveness to the user.
In a non multi threaded environment, a server listens to the port for some
request and when the request comes, it processes the request and then resume
listening to another request. The time taken while processing of request
makes other users wait unnecessarily. Instead a better approach would be to
pass the request to a worker thread and continue listening to port.
For example, a multi threaded web browser allow user interaction in one
thread while an video is being loaded in another thread. So instead of waiting
for the whole web-page to load the user can continue viewing some portion of
the web-page.
2. Resource Sharing –
Processes may share resources only through techniques such as-
 Message Passing
 Shared Memory
Such techniques must be explicitly organized by programmer. However,
threads share the memory and the resources of the process to which they
belong by default.
The benefit of sharing code and data is that it allows an application to have
several threads of activity within same address space.
3. Economy –
Allocating memory and resources for process creation is a costly job in terms
of time and space.
Since, threads share memory with the process it belongs, it is more
economical to create and context switch threads. Generally much more time
is consumed in creating and managing processes than in threads.
In Solaris, for example, creating process is 30 times slower than creating
threads and context switching is 5 times slower.
4. Scalability –
The benefits of multi-programming greatly increase in case of multiprocessor
architecture, where threads may be running parallel on multiple processors. If
there is only one thread then it is not possible to divide the processes into smaller
tasks that different processors can perform.
Single threaded process can run only on one processor regardless of how many
processors are available.
Multi-threading on a multiple CPU machine increases parallelism.

You might also like