SlideShare a Scribd company logo
1 of 19
Download to read offline
Thread
What?
A thread is called a lightweight process:
●
it is comprised over a thread ID, program counter, a register set
and a stack
●
it shares with other threads belonging to the same process its code
section, data section and other OS resources (e.g., open files)
●
a process that has multiples threads can do more than one task at a
time
A traditional (or heavyweight) process has a single thread of
control.

Operating System 2011/2012
Why?
A single application may be required to perform several
similar tasks (such as Web server and Word processor).
●
One solution is to have the a single process for each Web
request or Word document. Each process perform on a single
request/document => a separate process is created to service
that request.
●
Process creation is time consuming and resource intensive.
●
Rather than creating another process, the server will create a
new thread to service the request and resume listening for
additional requests.
●

Operating System 2011/2012
Single vs. Multithreaded Processes

Operating System 2011/2012
Benefits
Responsiveness
●
One part of a program can continue running even if
another part is blocked
●
Resource Sharing
●
Threads of the same process share the same memory
space and resources
●
Economy
●
Much less time consuming to create and manage threads
than processes
●
Scalability
●
Each thread can run in parallel on a different processor
●

Operating System 2011/2012
User Threads
Thread management done by user-level threads library is
without the intervention of the kernel
●
Fast to create and manager
●
If the kernel is single threaded, any user-level thread
performing a blocking system call will cause the entire
process to block
User thread libraries
●
POSIX Pthreads
●
Mach C-threads
●
Solaris 2 UI-threads
Operating System 2011/2012
Kernel Threads
Supported by the Kernel
●
Slower to create and manage than user threads
●
If thread performs a blocking system call, the kernel can
schedule another thread in the application for execution
●
In multi-processor environments, the kernel can schedule
threads on multiple processors
Examples
●
Windows 95/98/NT/2000
●
Solaris
●
Linux
Operating System 2011/2012
Multithreading Models

●

One-to-One

●

Many-to-One

●

Many-to-Many

Operating System 2011/2012
One-to-One
Each user-level thread maps to kernel thread.
●
Another thread can run when one thread makes a blocking
call
●
Multiple threads an run in parallel on a MP machine
●
Overhead of creating a kernel thread for each user thread
●
Most implementations limit the number of threads supported
Examples
●
Windows 95-2000
●
OS/2
●
Linux

Operating System 2011/2012
Many-to-One
Many user-level threads mapped to single kernel thread.
●
Efficient - thread management done in user space
●
Entire process will block if a thread makes a blocking
system call
●
Only one thread can access the kernel, no parallel processing
in MP environment

Operating System 2011/2012
Many-to-Many
Allows many user level threads to be mapped to smaller or
equal number of kernel threads.
As many user threads as necessary can be created.
Corresponding kernel threads can run in parallel on a
multiprocessor.
When a thread performs a
blocking system call, the kernel
can schedule another thread for
execution.
Allows true concurrency in a MP
environment and does not
restrict number of threads that
can be created.
Operating System 2011/2012
Two Level Model
Has all the functionality of the many-to many model but also
allows a user-level thread to be bound to a kernel thread

Operating System 2011/2012
API
API for creating and managing threads
●
No kernel support, strictly in use space so no system calls
involved
●
Kernel level directly supported by the OS. All code and data
structures for the library exits in kernel spacer
●
An API call typically invokes a system call
●
Three main libraries in use
●
POSIX (Portable Operating System Interface) threads
●
Win32
●
Java

Operating System 2011/2012
Pthreads
Pthreads refers to the POSIX standard (IEEE 1003.1c)
deifining an API for thread creation and synchronization
●
Pthreads is an IEEE and Open Group certified product
●
The Open Group is a vendor-neutral and technology-neutral
consortium, whose vision of Boundaryless Information
Flow™ will enable access to integrated information, within
and among enterprises, based on open standards and global
interoperability.
●
This is a specification for thread behavior not an
implementation
●
Implemented by Solaris, Linux, MacOS X and Tru64
●

Operating System 2011/2012
Windows XP Threads
Implements the one-to-one mapping
●
Each thread contains: a thread id, register set, separate user
and kernel stacks private data storage area
●
A Windows XP application runs as a separate process and
each process may contain one or more threads
●
The register set, stacks, and private storage area are known
as the context of the threads
●
The primary data structures of a thread include: ETHREAD
(executive thread block), KTHREAD (kernel thread block),
TEB (thread environment block)
●
Also provides support for a fiber library which implements
the many-to-many model
●

Operating System 2011/2012
Java
Java threads may be created by extending the Thread class or
implementing the Runnable interface
●
Java threads are managed by the JVM
●
Not really a user- or kernel-level thread, support provided at
the language level
●
No global data in Java, data is shared by passing the
reference to the appropriate threads
●
The JVM specification does not indicate how threads should
be mapped to the underlying OS
●
Windows 95/98/NT/2000 use the one-to-one model (each
Java thread maps to a kernel thread)
●
Solaris 2 used the many-to-many model
●

Operating System 2011/2012
Java Thread State

Operating System 2011/2012
Thread pools
Though creating a new thread is more efficient than creating a
new process, there are still some issues
There is a delay in creating the thread and it will be discarded
when done
There is no limit put on how many threads are allowed to be
created and system resources could be exhausted
Create a number of threads in a pool where they await work.
When needed, thread is awoken, when finished returns to pool
to await more work

Operating System 2011/2012
Thread pools – cont.
Advantages:
●

●

●

Usually slightly faster to service a request with an existing
thread than create a new thread
Allows the number of threads in the application(s) to be
bound to the size of the pool
Size of the pool can be dynamically adjusted based on usage
patterns

Operating System 2011/2012

More Related Content

What's hot

Operating System 4
Operating System 4Operating System 4
Operating System 4
tech2click
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
Sonali Chauhan
 

What's hot (20)

Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Threading
ThreadingThreading
Threading
 
OS_Ch5
OS_Ch5OS_Ch5
OS_Ch5
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
4 threads
4 threads4 threads
4 threads
 
Multithreading
Multithreading Multithreading
Multithreading
 
Thread presentation
Thread presentationThread presentation
Thread presentation
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 
threads and its types ....in operating system ..
threads and its types ....in operating system ..threads and its types ....in operating system ..
threads and its types ....in operating system ..
 
Thread
ThreadThread
Thread
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Multi threading models
Multi threading modelsMulti threading models
Multi threading models
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Threads
ThreadsThreads
Threads
 
Threads
ThreadsThreads
Threads
 
Thread management
Thread management Thread management
Thread management
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 

Viewers also liked (10)

Threads c sharp
Threads c sharpThreads c sharp
Threads c sharp
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
 
Real time web
Real time webReal time web
Real time web
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Threading
ThreadingThreading
Threading
 
multi threading
multi threadingmulti threading
multi threading
 
Multi threading design pattern
Multi threading design patternMulti threading design pattern
Multi threading design pattern
 
C# Advanced L04-Threading
C# Advanced L04-ThreadingC# Advanced L04-Threading
C# Advanced L04-Threading
 
Threads c sharp
Threads c sharpThreads c sharp
Threads c sharp
 
Threading in c#
Threading in c#Threading in c#
Threading in c#
 

Similar to Thread

OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 
Posix threads(asha)
Posix threads(asha)Posix threads(asha)
Posix threads(asha)
Nagarajan
 
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
LieYah Daliah
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
Trinh Phuc Tho
 

Similar to Thread (20)

Concept of thread
Concept of threadConcept of thread
Concept of thread
 
W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
 
Threads & Concurrency
Threads & Concurrency Threads & Concurrency
Threads & Concurrency
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
 
Lecture 3- Threads.pdf
Lecture 3- Threads.pdfLecture 3- Threads.pdf
Lecture 3- Threads.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Threads are using in operating systems.pptx
Threads are using in operating systems.pptxThreads are using in operating systems.pptx
Threads are using in operating systems.pptx
 
Thread
ThreadThread
Thread
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
 
Epc 3.ppt
Epc 3.pptEpc 3.ppt
Epc 3.ppt
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
 
Posix threads(asha)
Posix threads(asha)Posix threads(asha)
Posix threads(asha)
 
Architecture of web servers
Architecture of web serversArchitecture of web servers
Architecture of web servers
 
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Processes and Threads in Windows Vista
Processes and Threads in Windows VistaProcesses and Threads in Windows Vista
Processes and Threads in Windows Vista
 

More from Mustafa Ugur Oduncu (8)

Windows server 2008
Windows server 2008 Windows server 2008
Windows server 2008
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Main Memory
Main MemoryMain Memory
Main Memory
 
Shared Memory
Shared MemoryShared Memory
Shared Memory
 
Scheduling
SchedulingScheduling
Scheduling
 
Processes
ProcessesProcesses
Processes
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Thread

  • 2. What? A thread is called a lightweight process: ● it is comprised over a thread ID, program counter, a register set and a stack ● it shares with other threads belonging to the same process its code section, data section and other OS resources (e.g., open files) ● a process that has multiples threads can do more than one task at a time A traditional (or heavyweight) process has a single thread of control. Operating System 2011/2012
  • 3. Why? A single application may be required to perform several similar tasks (such as Web server and Word processor). ● One solution is to have the a single process for each Web request or Word document. Each process perform on a single request/document => a separate process is created to service that request. ● Process creation is time consuming and resource intensive. ● Rather than creating another process, the server will create a new thread to service the request and resume listening for additional requests. ● Operating System 2011/2012
  • 4. Single vs. Multithreaded Processes Operating System 2011/2012
  • 5. Benefits Responsiveness ● One part of a program can continue running even if another part is blocked ● Resource Sharing ● Threads of the same process share the same memory space and resources ● Economy ● Much less time consuming to create and manage threads than processes ● Scalability ● Each thread can run in parallel on a different processor ● Operating System 2011/2012
  • 6. User Threads Thread management done by user-level threads library is without the intervention of the kernel ● Fast to create and manager ● If the kernel is single threaded, any user-level thread performing a blocking system call will cause the entire process to block User thread libraries ● POSIX Pthreads ● Mach C-threads ● Solaris 2 UI-threads Operating System 2011/2012
  • 7. Kernel Threads Supported by the Kernel ● Slower to create and manage than user threads ● If thread performs a blocking system call, the kernel can schedule another thread in the application for execution ● In multi-processor environments, the kernel can schedule threads on multiple processors Examples ● Windows 95/98/NT/2000 ● Solaris ● Linux Operating System 2011/2012
  • 9. One-to-One Each user-level thread maps to kernel thread. ● Another thread can run when one thread makes a blocking call ● Multiple threads an run in parallel on a MP machine ● Overhead of creating a kernel thread for each user thread ● Most implementations limit the number of threads supported Examples ● Windows 95-2000 ● OS/2 ● Linux Operating System 2011/2012
  • 10. Many-to-One Many user-level threads mapped to single kernel thread. ● Efficient - thread management done in user space ● Entire process will block if a thread makes a blocking system call ● Only one thread can access the kernel, no parallel processing in MP environment Operating System 2011/2012
  • 11. Many-to-Many Allows many user level threads to be mapped to smaller or equal number of kernel threads. As many user threads as necessary can be created. Corresponding kernel threads can run in parallel on a multiprocessor. When a thread performs a blocking system call, the kernel can schedule another thread for execution. Allows true concurrency in a MP environment and does not restrict number of threads that can be created. Operating System 2011/2012
  • 12. Two Level Model Has all the functionality of the many-to many model but also allows a user-level thread to be bound to a kernel thread Operating System 2011/2012
  • 13. API API for creating and managing threads ● No kernel support, strictly in use space so no system calls involved ● Kernel level directly supported by the OS. All code and data structures for the library exits in kernel spacer ● An API call typically invokes a system call ● Three main libraries in use ● POSIX (Portable Operating System Interface) threads ● Win32 ● Java Operating System 2011/2012
  • 14. Pthreads Pthreads refers to the POSIX standard (IEEE 1003.1c) deifining an API for thread creation and synchronization ● Pthreads is an IEEE and Open Group certified product ● The Open Group is a vendor-neutral and technology-neutral consortium, whose vision of Boundaryless Information Flow™ will enable access to integrated information, within and among enterprises, based on open standards and global interoperability. ● This is a specification for thread behavior not an implementation ● Implemented by Solaris, Linux, MacOS X and Tru64 ● Operating System 2011/2012
  • 15. Windows XP Threads Implements the one-to-one mapping ● Each thread contains: a thread id, register set, separate user and kernel stacks private data storage area ● A Windows XP application runs as a separate process and each process may contain one or more threads ● The register set, stacks, and private storage area are known as the context of the threads ● The primary data structures of a thread include: ETHREAD (executive thread block), KTHREAD (kernel thread block), TEB (thread environment block) ● Also provides support for a fiber library which implements the many-to-many model ● Operating System 2011/2012
  • 16. Java Java threads may be created by extending the Thread class or implementing the Runnable interface ● Java threads are managed by the JVM ● Not really a user- or kernel-level thread, support provided at the language level ● No global data in Java, data is shared by passing the reference to the appropriate threads ● The JVM specification does not indicate how threads should be mapped to the underlying OS ● Windows 95/98/NT/2000 use the one-to-one model (each Java thread maps to a kernel thread) ● Solaris 2 used the many-to-many model ● Operating System 2011/2012
  • 17. Java Thread State Operating System 2011/2012
  • 18. Thread pools Though creating a new thread is more efficient than creating a new process, there are still some issues There is a delay in creating the thread and it will be discarded when done There is no limit put on how many threads are allowed to be created and system resources could be exhausted Create a number of threads in a pool where they await work. When needed, thread is awoken, when finished returns to pool to await more work Operating System 2011/2012
  • 19. Thread pools – cont. Advantages: ● ● ● Usually slightly faster to service a request with an existing thread than create a new thread Allows the number of threads in the application(s) to be bound to the size of the pool Size of the pool can be dynamically adjusted based on usage patterns Operating System 2011/2012