0% found this document useful (0 votes)
2 views2 pages

Thread in Operating System

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Thread in Operating System

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Thread in Operating System

A thread is a single sequence stream within a process. Threads are also called lightweight processes as they possess
some of the properties of processes. Each thread belongs to exactly one process.

• In an operating system that supports multithreading, the process can consist of many threads. But threads can
be effective only if the CPU is more than 1 otherwise two threads have to context switch for that single CPU.

• All threads belonging to the same process share – code section, data section, and OS resources (e.g. open files
and signals)

• But each thread has its own (thread control block) – thread ID, program counter, register set, and a stack

• Any operating system process can execute a thread. we can say that single process can have multiple threads.

Why Do We Need Thread?

• Threads run in concurrent manner that improves the application performance. Each such thread has its own CPU
state and stack, but they share the address space of the process and the environment. For example, when we
work on Microsoft Word or Google Docs, we notice that while we are typing, multiple things happen together
(formatting is applied, page is changed and auto save happens).

• Threads can share common data so they do not need to use inter-process communication. Like the processes,
threads also have states like ready, executing, blocked, etc.

• Priority can be assigned to the threads just like the process, and the highest priority thread is scheduled first.

• Each thread has its own Thread Control Block (TCB). Like the process, a context switch occurs for the thread, and
register contents are saved in (TCB). As threads share the same address space and resources, synchronization is
also required for the various activities of the thread.

Components of Threads

These are the basic components of the Operating System.

• Stack Space: Stores local variables, function calls, and return addresses specific to the thread.

• Register Set: Hold temporary data and intermediate results for the thread’s execution.

• Program Counter: Tracks the current instruction being executed by the thread.

Types of Thread in Operating System

Threads are of two types. These are described below.

• User Level Thread

• Kernel Level Thread

1. User Level Thread

User Level Thread is a type of thread that is not created using system
calls. The kernel has no work in the management of user-level threads.
User-level threads can be easily implemented by the user. In case
when user-level threads are single-handed processes, kernel-level
thread manages them. Let’s look at the advantages and disadvantages
of User-Level Thread.

2. Kernel Level Threads

A kernel Level Thread is a type of thread that can recognize the Operating system easily. Kernel Level Threads has its own
thread table where it keeps track of the system. The operating System Kernel helps in managing threads. Kernel Threads
have somehow longer context switching time. Kernel helps in the management of threads.
Difference Between Process and Thread

The primary difference is that threads within the same process run in a shared memory space, while processes run in
separate memory spaces. Threads are not independent of one another like processes are, and as a result, threads share
with other threads their code section, data section, and OS resources (like open files and signals). But, like a process, a
thread has its own program counter (PC), register set, and stack space.

Benefits of Thread in Operating System

• Responsiveness: If the process is divided into multiple threads, if one thread completes its execution, then its
output can be immediately returned.

• Faster context switch: Context switch time between threads is lower compared to the process context switch.
Process context switching requires more overhead from the CPU.

• Effective utilization of multiprocessor system: If we have multiple threads in a single process, then we can
schedule multiple threads on multiple processors. This will make process execution faster.

• Resource sharing: Resources like code, data, and files can be shared among all threads within a process. Note:
Stacks and registers can’t be shared among the threads. Each thread has its own stack and registers.

• Communication: Communication between multiple threads is easier, as the threads share a common address
space. while in the process we have to follow some specific communication techniques for communication
between the two processes.

• 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.

Thread in Operating System – FAQs

What is thread state in operating system?

There are four different states of a thread.

• new

• runnable

• blocked

• terminated

Why thread is better than process?

Threads require fewer resources whereas process require more resources. that is why thread is better than process.

Why is multithreading faster?

While the computer system’s processor only carries out one instruction at a time when multithreading is used, various
threads from several applications are carried out so quickly that it appears as though the programs are running
simultaneously.

What is thread synchronization?

Thread synchronization is the coordination of threads to ensure proper execution and prevent conflicts when accessing
shared resources.

What is deadlock in OS?

A deadlock is a situation where a set of processes is blocked because each process is holding a resource and waiting for
another resource acquired by some other process.

You might also like