SlideShare a Scribd company logo
Threads
in operating systems
By
Syeda Farheen Naz
Haji Gul
Sajid
Mudassir
What are Threads?
• Thread is an execution unit which consists of its own program
counter, a stack, and a set of registers. Threads are also known
as Lightweight processes.
• Threads are popular way to improve application through
parallelism.
• As each thread has its own independent resource for process
execution, multiple processes can be executed parallel by
increasing number of threads.
Why use Threads?
• Large multiprocessors need many computing entities (one per
CPU)
• Switching between processes incurs high overhead
• With threads, an application can avoid per-process overheads
– Thread creation, deletion, switching cheaper than processes
• Threads have full access to address space (easy sharing)
• Threads can execute in parallel on multiprocessors
Single Threaded Approaches
• A single execution path per process, in which the concept of a
thread is not recognized, is referred to as a single-threaded
approach
• MS-DOS is an example of an OS that supports a single user
process and a single thread.
• some versions of UNIX also supported this type of process.
Multithreaded Approaches
• A Java run-time environment is a system of one process with
multiple threads; Windows also support multiple multithreaded
processes
Concurrent Execution on a Single-core System
Parallel Execution on a Multi core System
Types of Thread
There are two types of threads :
1. User level Thread management done by user-level threads
library(Pthreads,Win32 threads, Java threads)
2. Kernel level Supported by the Kernel/OS(Linux ,Windows
XP/2000)
8
Advantages and disadvantages of ULT
Advantages
• Thread switching does not
involve the kernel: no
mode switching, therefore
fast
• Scheduling can be
application specific:
choose the best algorithm
for the situation.
• Can run on any OS. We
only need a thread library
Disadvantages
• Most system calls are
blocking for processes. So
all threads within a process
will be implicitly blocked
• The kernel can only assign
processors to processes.
Two threads within the
same process cannot run
simultaneously on two
processors
9
Advantages and disadvantages of KLT
Advantages
• The kernel can schedule
multiple threads of the same
process on multiple
processors
• Blocking at thread level, not
process level
– If a thread blocks, the
CPU can be assigned to
another thread in the
same process
• Even the kernel routines can
be multithreaded
Disadvantages
• Thread switching always
involves the kernel. This
means 2 mode switches
per thread switch
• So it is slower compared to
User Level Threads
– (But faster than a full
process switch)
10
Few Implementation
Libraries
PThreads
• A POSIX standard (IEEE 1003.1c) API for thread creation and
synchronization
• API specifies behavior of the thread library, implementation is up
to development of the library
Windows Threads
• Implements the one-to-one mapping
• Each thread contains
– A thread id
– Register set
– Separate user and kernel stacks
– Private data storage area
11
Linux Threads
• Linux refers to them as tasks rather than threads
• Thread creation is done through clone() system call
• clone() allows a child task to share the address space of the parent
task (process)
Java Threads
• Java threads may be created by:
– Extending Thread class
– Implementing the Run able interface
• Java threads are managed by the JVM.
Cooperative Threads
• Cooperative threads use non pre-emptive scheduling
• Advantages:
– Simple
• Scientific apps
• Disadvantages:
– For badly written code
• Scheduler gets invoked only when Yield is called
• A thread could yield the processor when it blocks for I/O
Non-Cooperative Threads
• No explicit control passing among threads
• Rely on a scheduler to decide which thread to run
• A thread can be pre-empted at any point
• Often called pre-emptive threads
• Most modern thread packages use this approach.
Multithreading Models
The user threads must be mapped to kernel threads, by one of the
following strategies.
• Many-To-One Model
• One-To-One Model
• Many-To-Many Model
Many-To-One Model
• In the many-to-one model, many user-level threads are all
mapped onto a single kernel thread.
• Thread management is handled by the thread library in user space,
which is efficient in nature.
One-To-One Model
• The one-to-one model creates a separate kernel thread to
handle each and every user thread.
• Most implementations of this model place a limit on how
many threads can be created.
• Linux and Windows from 95 to XP implement the one-to-one
model for threads.
Many-To-Many Model
• The many-to-many model multiplexes any number of user
threads onto an equal or smaller number of kernel threads,
combining the best features of the one-to-one and many-to-one
models.
• Users can create any number of the threads.
• Blocking the kernel system calls does not block the entire
process.
• Processes can be split across multiple processors.
Thread Life Cycle in JAVA
The Life cycle of thread in Java is controlled by JVM. The Java thread states are as
follows.
 New
The thread is in new state if you create an instance of Thread class but before
the invocation of start() method.
 Runnable
The thread is in runnable state after invocation of start() method, but the
thread scheduler has not selected it to be the running thread.
 Running
The thread is in running state if the thread scheduler has selected it.
 Non-Runnable (Blocked)
This is the state when the thread is still alive, but is currently not eligible to
run.
 Terminated
A thread is terminated when run() method terminates.
Non
Runnable
(Bocked)
New
Runnable
Running
Terminated
Start()
Sleep, block on
I/O, suspend,
wait
Sleep done, I/O
complete,
resume, notify
Thread Control Block
• Thread Control Block (TCB) is a data structure in the operating system kernel
which contains thread-specific information needed to manage it. The TCB is "the
manifestation of a thread in an operating system".
• An example of information contained within a TCB is:
• Stack pointer: Points to thread's stack in the process
• Program counter
• State of the thread (running, ready, waiting, start, done)
• Thread's register values
• Pointer to the Process control block (PCB) of the process that the thread lives on
The Thread Control Block acts as a library of information about the threads in a
system. Specific information is stored in the thread control block highlighting
important information about each thread.
Thread

More Related Content

What's hot

Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
Shubham Sharma
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
rprajat007
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
meet darji
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
tamizh arthanari
 
Kernel. Operating System
Kernel. Operating SystemKernel. Operating System
Kernel. Operating System
pratikkadam78
 
Operating system Memory management
Operating system Memory management Operating system Memory management
Operating system Memory management
Shashank Asthana
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
Rajan Shah
 
Processors and its Types
Processors and its TypesProcessors and its Types
Processors and its Types
Nimrah Shahbaz
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
Mukesh Chinta
 
Thread
ThreadThread
Thread
Mohd Arif
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
Sonali Chauhan
 
Context switching
Context switchingContext switching
Context switching
DarakhshanNayyab
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
Nishant Joshi
 
Demand paging
Demand pagingDemand paging
Demand paging
SwaroopSorte
 
Chapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage SystemsChapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage Systems
Wayne Jones Jnr
 
RAM(Random Access Memory)
RAM(Random Access Memory)RAM(Random Access Memory)
RAM(Random Access Memory)
JaneAlamAdnan
 
MemoryManagementStrategies.ppt
MemoryManagementStrategies.pptMemoryManagementStrategies.ppt
MemoryManagementStrategies.ppt
PaulRajasingh2
 
Presentation on C.P.U
Presentation on C.P.UPresentation on C.P.U
Presentation on C.P.U
fgdgxvbm98
 
Operating system components
Operating system componentsOperating system components
Operating system components
Syed Zaid Irshad
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Deepika Balichwal
 

What's hot (20)

Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Kernel. Operating System
Kernel. Operating SystemKernel. Operating System
Kernel. Operating System
 
Operating system Memory management
Operating system Memory management Operating system Memory management
Operating system Memory management
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Processors and its Types
Processors and its TypesProcessors and its Types
Processors and its Types
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
 
Thread
ThreadThread
Thread
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Context switching
Context switchingContext switching
Context switching
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Demand paging
Demand pagingDemand paging
Demand paging
 
Chapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage SystemsChapter 12 - Mass Storage Systems
Chapter 12 - Mass Storage Systems
 
RAM(Random Access Memory)
RAM(Random Access Memory)RAM(Random Access Memory)
RAM(Random Access Memory)
 
MemoryManagementStrategies.ppt
MemoryManagementStrategies.pptMemoryManagementStrategies.ppt
MemoryManagementStrategies.ppt
 
Presentation on C.P.U
Presentation on C.P.UPresentation on C.P.U
Presentation on C.P.U
 
Operating system components
Operating system componentsOperating system components
Operating system components
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 

Viewers also liked

Threads
ThreadsThreads
Threads
Shivam Singh
 
OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
sgpraju
 
Capital budgeting by huzaifah irshaad
Capital budgeting by huzaifah irshaad Capital budgeting by huzaifah irshaad
Capital budgeting by huzaifah irshaad
HuzaifaIrshaad
 
Business Seminar Final Paper
Business Seminar Final PaperBusiness Seminar Final Paper
Business Seminar Final Paper
Maple Yuen
 
Getting the Most Out Of Your Lecture (1)
Getting the Most Out Of Your Lecture (1)Getting the Most Out Of Your Lecture (1)
Getting the Most Out Of Your Lecture (1)
Yvette Dodson
 
Hydraulic Quick Couplings
Hydraulic Quick CouplingsHydraulic Quick Couplings
Hydraulic Quick Couplings
Leo Liu
 
Citations UCEM (TEXTE 22.II.7.4)
Citations UCEM (TEXTE 22.II.7.4)Citations UCEM (TEXTE 22.II.7.4)
Citations UCEM (TEXTE 22.II.7.4)
Pierrot Caron
 
Oracle EBS
Oracle EBSOracle EBS
Oracle EBS
Serge R
 
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
Pierrot Caron
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
mayacendana
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
Peter Tröger
 
4 estadísticas de las imágenes satelitales
4 estadísticas de las imágenes satelitales4 estadísticas de las imágenes satelitales
4 estadísticas de las imágenes satelitales
Jenny Andrea
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
cscarcas
 
Ao rei dos reis consagro tudo o que
Ao rei dos reis consagro tudo o queAo rei dos reis consagro tudo o que
Ao rei dos reis consagro tudo o que
Aline Vasconcelos
 
masup
masup masup
masup
Marana Mass
 
CURRICULUM VITAE_Dec 2016
CURRICULUM VITAE_Dec 2016CURRICULUM VITAE_Dec 2016
CURRICULUM VITAE_Dec 2016
Dhanapal P
 
Some lessons of Weaving
Some lessons of WeavingSome lessons of Weaving
Some lessons of Weaving
Deepanshu Singh Kushwaha
 
Atribulado coração,em cristo alívio encontrarás
Atribulado coração,em cristo alívio encontrarásAtribulado coração,em cristo alívio encontrarás
Atribulado coração,em cristo alívio encontrarás
Aline Vasconcelos
 

Viewers also liked (18)

Threads
ThreadsThreads
Threads
 
OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
 
Capital budgeting by huzaifah irshaad
Capital budgeting by huzaifah irshaad Capital budgeting by huzaifah irshaad
Capital budgeting by huzaifah irshaad
 
Business Seminar Final Paper
Business Seminar Final PaperBusiness Seminar Final Paper
Business Seminar Final Paper
 
Getting the Most Out Of Your Lecture (1)
Getting the Most Out Of Your Lecture (1)Getting the Most Out Of Your Lecture (1)
Getting the Most Out Of Your Lecture (1)
 
Hydraulic Quick Couplings
Hydraulic Quick CouplingsHydraulic Quick Couplings
Hydraulic Quick Couplings
 
Citations UCEM (TEXTE 22.II.7.4)
Citations UCEM (TEXTE 22.II.7.4)Citations UCEM (TEXTE 22.II.7.4)
Citations UCEM (TEXTE 22.II.7.4)
 
Oracle EBS
Oracle EBSOracle EBS
Oracle EBS
 
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
LEÇON 72 – Avoir des rancœurs est une attaque contre le plan de Dieu pour le ...
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 
Operating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - ThreadsOperating Systems 1 (7/12) - Threads
Operating Systems 1 (7/12) - Threads
 
4 estadísticas de las imágenes satelitales
4 estadísticas de las imágenes satelitales4 estadísticas de las imágenes satelitales
4 estadísticas de las imágenes satelitales
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
 
Ao rei dos reis consagro tudo o que
Ao rei dos reis consagro tudo o queAo rei dos reis consagro tudo o que
Ao rei dos reis consagro tudo o que
 
masup
masup masup
masup
 
CURRICULUM VITAE_Dec 2016
CURRICULUM VITAE_Dec 2016CURRICULUM VITAE_Dec 2016
CURRICULUM VITAE_Dec 2016
 
Some lessons of Weaving
Some lessons of WeavingSome lessons of Weaving
Some lessons of Weaving
 
Atribulado coração,em cristo alívio encontrarás
Atribulado coração,em cristo alívio encontrarásAtribulado coração,em cristo alívio encontrarás
Atribulado coração,em cristo alívio encontrarás
 

Similar to Thread

Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
Kumbirai Junior Muzavazi
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.ppt
aakarshsiwani1
 
1 Multithreading basics.pptx
1 Multithreading basics.pptx1 Multithreading basics.pptx
1 Multithreading basics.pptx
YojanaFegade
 
THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid
noman zahid
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptx
piyushlohia1857
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
amadayshwan
 
thread os.pptx
thread os.pptxthread os.pptx
thread os.pptx
SANJUSANJEEVTOPPO
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
AnyapuPranav
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
Welly Dian Astika
 
4 threads
4 threads4 threads
4 threads
Dr. Loganathan R
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
Vaibhav Khanna
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
BalasundaramSr
 
Threads
ThreadsThreads
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
sandhyakiran10
 
OS Thr schd.ppt
OS Thr schd.pptOS Thr schd.ppt
OS Thr schd.ppt
ZohairMughal1
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
madan r
 
Java threading
Java threadingJava threading
Java threading
Chinh Ngo Nguyen
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 

Similar to Thread (20)

Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
chapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.pptchapter4-processes nd processors in DS.ppt
chapter4-processes nd processors in DS.ppt
 
1 Multithreading basics.pptx
1 Multithreading basics.pptx1 Multithreading basics.pptx
1 Multithreading basics.pptx
 
THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid THREADS of Operating System by Noman Zahid
THREADS of Operating System by Noman Zahid
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptx
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
 
thread os.pptx
thread os.pptxthread os.pptx
thread os.pptx
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
 
4 threads
4 threads4 threads
4 threads
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
 
Threads
ThreadsThreads
Threads
 
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
8.-OBJECT-ORIENTED-PROGRAMMING-USING-JAVA-Multithreading.pptx
 
OS Thr schd.ppt
OS Thr schd.pptOS Thr schd.ppt
OS Thr schd.ppt
 
U4 JAVA.pptx
U4 JAVA.pptxU4 JAVA.pptx
U4 JAVA.pptx
 
Java threading
Java threadingJava threading
Java threading
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 

Recently uploaded

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 

Thread

  • 1. Threads in operating systems By Syeda Farheen Naz Haji Gul Sajid Mudassir
  • 2. What are Threads? • Thread is an execution unit which consists of its own program counter, a stack, and a set of registers. Threads are also known as Lightweight processes. • Threads are popular way to improve application through parallelism. • As each thread has its own independent resource for process execution, multiple processes can be executed parallel by increasing number of threads.
  • 3. Why use Threads? • Large multiprocessors need many computing entities (one per CPU) • Switching between processes incurs high overhead • With threads, an application can avoid per-process overheads – Thread creation, deletion, switching cheaper than processes • Threads have full access to address space (easy sharing) • Threads can execute in parallel on multiprocessors
  • 4. Single Threaded Approaches • A single execution path per process, in which the concept of a thread is not recognized, is referred to as a single-threaded approach • MS-DOS is an example of an OS that supports a single user process and a single thread. • some versions of UNIX also supported this type of process.
  • 5. Multithreaded Approaches • A Java run-time environment is a system of one process with multiple threads; Windows also support multiple multithreaded processes
  • 6. Concurrent Execution on a Single-core System Parallel Execution on a Multi core System
  • 7. Types of Thread There are two types of threads : 1. User level Thread management done by user-level threads library(Pthreads,Win32 threads, Java threads) 2. Kernel level Supported by the Kernel/OS(Linux ,Windows XP/2000)
  • 8. 8 Advantages and disadvantages of ULT Advantages • Thread switching does not involve the kernel: no mode switching, therefore fast • Scheduling can be application specific: choose the best algorithm for the situation. • Can run on any OS. We only need a thread library Disadvantages • Most system calls are blocking for processes. So all threads within a process will be implicitly blocked • The kernel can only assign processors to processes. Two threads within the same process cannot run simultaneously on two processors
  • 9. 9 Advantages and disadvantages of KLT Advantages • The kernel can schedule multiple threads of the same process on multiple processors • Blocking at thread level, not process level – If a thread blocks, the CPU can be assigned to another thread in the same process • Even the kernel routines can be multithreaded Disadvantages • Thread switching always involves the kernel. This means 2 mode switches per thread switch • So it is slower compared to User Level Threads – (But faster than a full process switch)
  • 10. 10 Few Implementation Libraries PThreads • A POSIX standard (IEEE 1003.1c) API for thread creation and synchronization • API specifies behavior of the thread library, implementation is up to development of the library Windows Threads • Implements the one-to-one mapping • Each thread contains – A thread id – Register set – Separate user and kernel stacks – Private data storage area
  • 11. 11 Linux Threads • Linux refers to them as tasks rather than threads • Thread creation is done through clone() system call • clone() allows a child task to share the address space of the parent task (process) Java Threads • Java threads may be created by: – Extending Thread class – Implementing the Run able interface • Java threads are managed by the JVM.
  • 12. Cooperative Threads • Cooperative threads use non pre-emptive scheduling • Advantages: – Simple • Scientific apps • Disadvantages: – For badly written code • Scheduler gets invoked only when Yield is called • A thread could yield the processor when it blocks for I/O
  • 13. Non-Cooperative Threads • No explicit control passing among threads • Rely on a scheduler to decide which thread to run • A thread can be pre-empted at any point • Often called pre-emptive threads • Most modern thread packages use this approach.
  • 14. Multithreading Models The user threads must be mapped to kernel threads, by one of the following strategies. • Many-To-One Model • One-To-One Model • Many-To-Many Model
  • 15. Many-To-One Model • In the many-to-one model, many user-level threads are all mapped onto a single kernel thread. • Thread management is handled by the thread library in user space, which is efficient in nature.
  • 16. One-To-One Model • The one-to-one model creates a separate kernel thread to handle each and every user thread. • Most implementations of this model place a limit on how many threads can be created. • Linux and Windows from 95 to XP implement the one-to-one model for threads.
  • 17. Many-To-Many Model • The many-to-many model multiplexes any number of user threads onto an equal or smaller number of kernel threads, combining the best features of the one-to-one and many-to-one models. • Users can create any number of the threads. • Blocking the kernel system calls does not block the entire process. • Processes can be split across multiple processors.
  • 18. Thread Life Cycle in JAVA The Life cycle of thread in Java is controlled by JVM. The Java thread states are as follows.  New The thread is in new state if you create an instance of Thread class but before the invocation of start() method.  Runnable The thread is in runnable state after invocation of start() method, but the thread scheduler has not selected it to be the running thread.  Running The thread is in running state if the thread scheduler has selected it.  Non-Runnable (Blocked) This is the state when the thread is still alive, but is currently not eligible to run.  Terminated A thread is terminated when run() method terminates.
  • 19. Non Runnable (Bocked) New Runnable Running Terminated Start() Sleep, block on I/O, suspend, wait Sleep done, I/O complete, resume, notify
  • 20. Thread Control Block • Thread Control Block (TCB) is a data structure in the operating system kernel which contains thread-specific information needed to manage it. The TCB is "the manifestation of a thread in an operating system". • An example of information contained within a TCB is: • Stack pointer: Points to thread's stack in the process • Program counter • State of the thread (running, ready, waiting, start, done) • Thread's register values • Pointer to the Process control block (PCB) of the process that the thread lives on The Thread Control Block acts as a library of information about the threads in a system. Specific information is stored in the thread control block highlighting important information about each thread.