0% found this document useful (0 votes)
81 views16 pages

Types of Threads in Operating Systems

A thread in an operating system is a lightweight process that allows for concurrent execution within a process, sharing resources like code and data. Threads improve performance by minimizing context switching time and providing efficient communication, but blocking a parent thread can halt all child threads. There are two main types of threads: user-level threads, which are managed by the user and faster to create, and kernel-level threads, which are managed by the operating system and can handle blocking operations without affecting other threads.

Uploaded by

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

Types of Threads in Operating Systems

A thread in an operating system is a lightweight process that allows for concurrent execution within a process, sharing resources like code and data. Threads improve performance by minimizing context switching time and providing efficient communication, but blocking a parent thread can halt all child threads. There are two main types of threads: user-level threads, which are managed by the user and faster to create, and kernel-level threads, which are managed by the operating system and can handle blocking operations without affecting other threads.

Uploaded by

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

UNIT NO-4

Operating System
WHAT IS THREAD IN OS?

 Thread is a sequential flow of tasks


within a process. Threads in OS can be of the
same or different types. Threads are used to
increase the performance of the applications.
 Each thread has its own program counter,

stack, and set of registers. But the threads of a


single process might share the same code and
data/file. Threads are also termed as
lightweight processes as they share
common resources.
 Eg: While playing a movie on a device the

audio and video are controlled by different


threads in the background.
PROCESS WITH SINGLE THREAD &
THREE THREAD (MULTITHREADING)
WHY DO WE NEED THREADS?

 Since threads use the same data and code,


the operational cost between threads is low.
 Creating and terminating a thread is faster

compared to creating or terminating a


process.
 Context switching is faster in threads
compared to processes.
DIFFERENCE BETWEEN
PROCESS AND THREADS
S.N. Process Threads
1. Process is heavy weight or resource Thread is light weight taking lesser
intensive. resources than a process.

2. Process switching needs interaction Thread switching does not need to


with operating system. interact with operating system.

3. In multiple processing environments All threads can share same set of open
each process executes the same code files, child processes.
but has its own memory and file
resources.
4. If one process is blocked then no other While one thread is blocked and waiting,
process can execute until the first second thread in the same task can run.
process is unblocked.

5. Multiple processes without using Multiple threaded processes use fewer


threads use more resources. resources.

6. In multiple processes each process One thread can read, write or


operates independently of the others. change another thread's data.

@PRAK
ADVANTAGES OF THREADS

• Thread minimizes context switching time.

• Use of threads provides concurrency within a process.

• Efficient communication.

• Economy- It is more economical to create and context


switch threads.

• Utilization of multiprocessor architectures to a greater


scale and efficiency.

@PRAK
DISADVANTAGES OF THREADS

• Blocking of parent threads will stop all child


thread.

@PRAK
WHY MULTITHREADING?

 Resource Sharing: Threads of a single


process share the same resources such
as code, data/file.
 Responsiveness: Program responsiveness
enables a program to run even if part of the
program is blocked or executing a lengthy
operation. Thus, increasing the
responsiveness to the user.
 Economy: It is more economical to use

threads as they share the resources of a


single process. On the other hand, creating
processes is expensive.
TYPES OF THREAD

 1. User Level Thread:


 User-level threads are implemented and managed
by the user and the kernel is not aware of it.
 User-level threads are implemented using
user-level libraries and the OS does not
recognize these threads.
 User-level thread is faster to create and
manage compared to kernel-level thread.
 Context switching in user-level threads is
faster.
 If one user-level thread performs a blocking
operation then the entire process gets blocked.
Eg: POSIX threads, Java threads, etc.
CONTINUE..
 2. Kernel level Thread:
 Kernel level threads are implemented and

managed by the OS.


 Kernel level threads are implemented using

system calls and Kernel level threads are


recognized by the OS.
 Kernel-level threads are slower to create and

manage compared to user-level threads.


 Context switching in a kernel-level thread

is slower.
 Even if one kernel-level thread performs a

blocking operation, it does not affect other


threads. Eg: Window Solaris.
USER LEVEL & KERNEL LEVEL
DIFFERENCE BETWEEN
ULT AND KLT :
S.N. User Level Thread Kernel Level Thread

1. User level thread are faster to create Kernel level thread are slower to create
and manage. and manage.

2. Implementation is by a thread library at Operating system supports creation of


the user level. kernel level threads.

3. ULT is generic and can run on any KLT is specific to the operating
operating system. system.

4. Multi-Threaded can not take Kernel routines themselves can be


advantages of multiprocessing. multithreaded.

@PRAK
MULTI-THREADING MODELS

 Multithreading allows the execution of


multiple parts of a program at the same
time.
 3 types of multi-threading models:

 Many to many model

 Many to one model

 One to one model


MANY TO MANY MODEL
MANY TO ONE MODEL
ONE TO ONE MODEL

You might also like