SlideShare a Scribd company logo
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

Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
Prakhar Maurya
 
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)
sonuu__
 
Operating System 4
Operating System 4Operating System 4
Operating System 4tech2click
 
Multithreading
Multithreading Multithreading
Multithreading
WafaQKhan
 
Thread presentation
Thread presentationThread presentation
Thread presentation
AAshish Ojha
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading modelsanoopkrishna2
 
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 ..
Nimrakhan89
 
Thread
ThreadThread
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
Kumbirai Junior Muzavazi
 
Multi threading models
Multi threading modelsMulti threading models
Multi threading models
DarakhshanNayyab
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-GalvinSonali Chauhan
 
Processes and threads
Processes and threadsProcesses and threads
Threads
ThreadsThreads
Threads
atikkazimca
 
Threads
ThreadsThreads
Threads
Shivam Singh
 
Thread management
Thread management Thread management
Thread management
Ayaan Adeel
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Arafat Hossan
 

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

Threads c sharp
Threads c sharpThreads c sharp
Threads c sharpDeivaa
 
Threading in C#
Threading in C#Threading in C#
Threading in C#
Medhat Dawoud
 
Real time web
Real time webReal time web
Real time web
Medhat Dawoud
 
multi threading
multi threadingmulti threading
Multi threading design pattern
Multi threading design patternMulti threading design pattern
Multi threading design patternYan Wang
 
C# Advanced L04-Threading
C# Advanced L04-ThreadingC# Advanced L04-Threading
C# Advanced L04-Threading
Mohammad Shaker
 
Threading in c#
Threading in c#Threading in c#
Threading in c#
gohsiauken
 

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

Multithreaded Programming in oprating system
Multithreaded Programming in oprating  systemMultithreaded Programming in oprating  system
Multithreaded Programming in oprating system
YOGENDRAMS
 
W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
alianwarr
 
Threads & Concurrency
Threads & Concurrency Threads & Concurrency
Threads & Concurrency
NomanMHasan
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
AnyapuPranav
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
Amanuelmergia
 
Lecture 3- Threads.pdf
Lecture 3- Threads.pdfLecture 3- Threads.pdf
Lecture 3- Threads.pdf
Amanuelmergia
 
Operating systems - Introduction to Threads
Operating systems - Introduction to ThreadsOperating systems - Introduction to Threads
Operating systems - Introduction to Threads
Chandrakant Divate
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
Dr. Mazin Mohamed alkathiri
 
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
MAmir53
 
Thread
ThreadThread
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
DanishMahmood23
 
Epc 3.ppt
Epc 3.pptEpc 3.ppt
Epc 3.ppt
CasmoletJ
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
Suvendu Kumar Dash
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
Nazir Ahmed
 
Posix threads(asha)
Posix threads(asha)Posix threads(asha)
Posix threads(asha)Nagarajan
 
Architecture of web servers
Architecture of web serversArchitecture of web servers
Architecture of web servers
Nicolas Vanhoren
 
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 SystemLieYah Daliah
 

Similar to Thread (20)

Multithreaded Programming in oprating system
Multithreaded Programming in oprating  systemMultithreaded Programming in oprating  system
Multithreaded Programming in oprating system
 
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
 
Operating systems - Introduction to Threads
Operating systems - Introduction to ThreadsOperating systems - Introduction to Threads
Operating systems - Introduction to Threads
 
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
 

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

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 

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