SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Operating Systems
Threads
Dr. Suresh Kumar Bhardwaj
Professor, CSE
MRIIRS
Manav Rachna International Institute of
Research and Studies, Faridabad
Threads
• The general structure of a process assumes that the process has an
address space with a single sequential execution sequence. Which leads
to low resource utilization
• Thread is a mechanism to provide multiple execution control to the
processes
• Thread has the following benefits:
– Responsiveness
– Resource Sharing
– Economy
– Utilization of MP Architectures
• Threads are classified as:
– user threads and
– the kernel threads
Single and Multithreaded Processes
User Level Threads
• Thread management done by user-level threads library rather than via
systems calls.
• Therefore, thread switching does not need to call operating system and to
cause interrupt to the kernel.
• In fact, the kernel knows nothing about user-level threads and manages
them as if they were single-threaded processes.
• Advantages :
– The most obvious advantage of this technique is that a user-level threads package can
be implemented on an Operating System that does not support threads.
– User-level threads do not require any modification to operating systems.
– Simple Representation : Each thread is represented simply by a PC, registers, stack and a
small control block, all stored in the user process address space.
– Simple Management : This simply means that creating a thread, switching between
threads and synchronization between threads can all be done without intervention of
the kernel.
– Fast and Efficient : Thread switching is not more expensive than a procedure call.
Disadvantages :
– There is a lack of coordination between threads and operating system kernel. Therefore,
process as whole gets one time slice irrespective of whether process has one thread or
even 1000 threads within it. It is up to each thread to relinquish control to other
threads.
– User-level threads require non-blocking systems call i.e., a multithreaded kernel.
Otherwise, entire process will be blocked in the kernel, even if there are runable threads
left in the processes. For example, if one thread causes a page fault, the process gets
blocked.
Three primary thread libraries:
– POSIX Pthreads
– Win32 threads
– Java threads
Kernel Level Threads
• The kernel knows about the threads and manages them.
• The kernel has a thread table that keeps track of all the threads in the system.
• In addition, the kernel also maintains the traditional process table to keep track of
the processes.
Advantages:
– Because kernel has full knowledge of all threads, Scheduler may decide to give more
time to a process having large number of threads than process having small number of
threads.
– Kernel-level threads are especially good for applications that frequently block.
Disadvantages:
– The kernel-level threads are slow and inefficient. For instance, threads operations are
hundred of times slower than that of user-level threads.
– Since kernel must manage and schedule threads as well as processes. It requires a full
thread control block (TCB) for each thread to maintain information about threads.
Multithreading Models
• Many-to-One
• One-to-One
• Many-to-Many
Many-to-One
• Many user-level threads mapped
to single kernel thread
• Examples:
– Solaris Green Threads
– GNU Portable Threads
One-to-One
• Each user-level thread maps to
kernel thread
• Examples
– Windows NT/XP/2000
– Linux
– Solaris 9 and later
Many-to-Many Model
• Allows many user level threads to
be mapped to many kernel
threads
• Allows the operating system to
create a sufficient number of
kernel threads
• Solaris prior to version 9
• Windows NT/2000 with the
ThreadFiber package
Java Threads
• Java threads are managed by the JVM
• Java threads may be created by:
– Extending Thread class
– Implementing the Runnable interface
Java Thread States
References
• Operating System Concepts: Silberschatz,
Wiley India, 9th edition
Manav Rachna International Institute of
Research and Studies, Faridabad

Weitere ähnliche Inhalte

Ähnlich wie Threads.ppt

Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
shreesha16
 
New Microsoft Word Document (3)
New Microsoft Word Document (3)New Microsoft Word Document (3)
New Microsoft Word Document (3)
Sid Hegde
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 

Ähnlich wie Threads.ppt (20)

Threads
ThreadsThreads
Threads
 
Threads
ThreadsThreads
Threads
 
Hardware Multithreading.pdf
Hardware Multithreading.pdfHardware Multithreading.pdf
Hardware Multithreading.pdf
 
Thread
ThreadThread
Thread
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
 
Thread
ThreadThread
Thread
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 
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
 
New Microsoft Word Document (3)
New Microsoft Word Document (3)New Microsoft Word Document (3)
New Microsoft Word Document (3)
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
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
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptx
 
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3
 
OS Thr schd.ppt
OS Thr schd.pptOS Thr schd.ppt
OS Thr schd.ppt
 
thread os.pptx
thread os.pptxthread os.pptx
thread os.pptx
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading models
 

Mehr von amadayshwan

Mehr von amadayshwan (10)

Page.Replacement.OS.ppt
Page.Replacement.OS.pptPage.Replacement.OS.ppt
Page.Replacement.OS.ppt
 
chap.4.memory.manag.ppt
chap.4.memory.manag.pptchap.4.memory.manag.ppt
chap.4.memory.manag.ppt
 
chapter10.masss storge.memory management.ppt
chapter10.masss storge.memory management.pptchapter10.masss storge.memory management.ppt
chapter10.masss storge.memory management.ppt
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
ch8 (2).ppt
ch8 (2).pptch8 (2).ppt
ch8 (2).ppt
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
osvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdfosvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdf
 
3 (2).ppt
3 (2).ppt3 (2).ppt
3 (2).ppt
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
CSS430_Deadlock.pptx
CSS430_Deadlock.pptxCSS430_Deadlock.pptx
CSS430_Deadlock.pptx
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Threads.ppt

  • 1. Operating Systems Threads Dr. Suresh Kumar Bhardwaj Professor, CSE MRIIRS Manav Rachna International Institute of Research and Studies, Faridabad
  • 2. Threads • The general structure of a process assumes that the process has an address space with a single sequential execution sequence. Which leads to low resource utilization • Thread is a mechanism to provide multiple execution control to the processes • Thread has the following benefits: – Responsiveness – Resource Sharing – Economy – Utilization of MP Architectures • Threads are classified as: – user threads and – the kernel threads
  • 4. User Level Threads • Thread management done by user-level threads library rather than via systems calls. • Therefore, thread switching does not need to call operating system and to cause interrupt to the kernel. • In fact, the kernel knows nothing about user-level threads and manages them as if they were single-threaded processes. • Advantages : – The most obvious advantage of this technique is that a user-level threads package can be implemented on an Operating System that does not support threads. – User-level threads do not require any modification to operating systems. – Simple Representation : Each thread is represented simply by a PC, registers, stack and a small control block, all stored in the user process address space. – Simple Management : This simply means that creating a thread, switching between threads and synchronization between threads can all be done without intervention of the kernel.
  • 5. – Fast and Efficient : Thread switching is not more expensive than a procedure call. Disadvantages : – There is a lack of coordination between threads and operating system kernel. Therefore, process as whole gets one time slice irrespective of whether process has one thread or even 1000 threads within it. It is up to each thread to relinquish control to other threads. – User-level threads require non-blocking systems call i.e., a multithreaded kernel. Otherwise, entire process will be blocked in the kernel, even if there are runable threads left in the processes. For example, if one thread causes a page fault, the process gets blocked. Three primary thread libraries: – POSIX Pthreads – Win32 threads – Java threads
  • 6. Kernel Level Threads • The kernel knows about the threads and manages them. • The kernel has a thread table that keeps track of all the threads in the system. • In addition, the kernel also maintains the traditional process table to keep track of the processes. Advantages: – Because kernel has full knowledge of all threads, Scheduler may decide to give more time to a process having large number of threads than process having small number of threads. – Kernel-level threads are especially good for applications that frequently block. Disadvantages: – The kernel-level threads are slow and inefficient. For instance, threads operations are hundred of times slower than that of user-level threads. – Since kernel must manage and schedule threads as well as processes. It requires a full thread control block (TCB) for each thread to maintain information about threads.
  • 7. Multithreading Models • Many-to-One • One-to-One • Many-to-Many
  • 8. Many-to-One • Many user-level threads mapped to single kernel thread • Examples: – Solaris Green Threads – GNU Portable Threads
  • 9. One-to-One • Each user-level thread maps to kernel thread • Examples – Windows NT/XP/2000 – Linux – Solaris 9 and later
  • 10. Many-to-Many Model • Allows many user level threads to be mapped to many kernel threads • Allows the operating system to create a sufficient number of kernel threads • Solaris prior to version 9 • Windows NT/2000 with the ThreadFiber package
  • 11. Java Threads • Java threads are managed by the JVM • Java threads may be created by: – Extending Thread class – Implementing the Runnable interface
  • 13. References • Operating System Concepts: Silberschatz, Wiley India, 9th edition Manav Rachna International Institute of Research and Studies, Faridabad