SlideShare a Scribd company logo
1 of 11
Multi Threading Models
Multithreading models
• There are three dominant models for
thread libraries, each with its own
trade-offs
– many threads on one LWP (many-to-one)
– one thread per LWP (one-to-one)
– many threads on many LWPs (many-to-
many)
• Similar models can apply on
scheduling kernel threads to real CPUs
Many-to-one
• In this model, the library maps all
threads to a single lightweight process
• Advantages:
– totally portable
– easy to do with few systems
dependencies
• Disadvantages:
– cannot take advantage of parallelism
– may have to block for synchronous
I/O
– there is a clever technique for
avoiding it
• Mainly used in language systems,
portable libraries
One-to-one
• In this model, the library maps each
thread to a different lightweight
process
• Advantages:
– can exploit parallelism, blocking
system calls
• Disadvantages:
– thread creation involves LWP
creation
– each thread takes up kernel
resources
– limiting the number of total threads
• Used in LinuxThreads and other
systems where LWP creation is not too
expensive
Many-to-many
• In this model, the library has two
kinds of threads: bound and
unbound
– bound threads are mapped
each to a single lightweight
process
– unbound threads may be
mapped to the same LWP
• Probably the best of both worlds
• Used in the Solaris
implementation of Pthreads (and
several other Unix
implementations)
High-Level Program Structure Ideas
• Boss/workers model
• Pipeline model
• Up-calls
• Keeping shared information consistent
using version stamps
Thread Design Patterns
Common ways of structuring programs using threads
• Boss/workers model
– boss gets assignments, dispatches tasks to workers
– variants (thread pool, single thread per connection…)
• Pipeline model
– do some work, pass partial result to next thread
• Up-calls
– fast control flow transfer for layered systems
• Version stamps
– technique for keeping information consistent
Boss/Workers
Boss: Worker:
forever { taskX();
get a request
switch(request)
case X: Fork (taskX)
case Y: Fork (taskY)
…
}
• Advantage: simplicity
• Disadvantage: bound on number of workers, overheard of
threads creation, contention if requests have
interdependencies
• Variants: fixed thread pool (aka workpile, workqueue),
producer/consumer relationship, workers determine what
needs to be performed…
Pipeline
• Each thread completes portion of a task,
and passes results
• like an assembly line or a processor
pipeline
• Advantages: trivial synchronization,
simplicity
• Disadvantages: limits degree of parallelism,
throughput driven by slowest stage,
handtuning needed
Up-calls
• Layered applications, e.g. network protocol stacks
have top-down and bottom-up flows
• Up-calls is a technique in which you structure layers
so that they can expect calls from below
• Thread pool of specialized threads in each layer
– essentially an up-call pipeline per connection
• Advantages: best when used with fast, synchronous
control flow transfer mechanisms or program
structuring tool
• Disadvantages: programming becomes more
complicated, synchronization required for top-
down
Version Stamps
• (Not a programming structure idea but
useful technique for any kind of distributed
environment)
• Maintain “version number” for shared data
– keep local cached copy of data
– check versions to determine if changed

More Related Content

What's hot

Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
myrajendra
 

What's hot (20)

Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Mainframe systems
Mainframe systemsMainframe systems
Mainframe systems
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
 
Parallel computing
Parallel computingParallel computing
Parallel computing
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Disk scheduling
Disk schedulingDisk scheduling
Disk scheduling
 
Implementation levels of virtualization
Implementation levels of virtualizationImplementation levels of virtualization
Implementation levels of virtualization
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Computer architecture multi processor
Computer architecture multi processorComputer architecture multi processor
Computer architecture multi processor
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 
Context switching
Context switchingContext switching
Context switching
 

Viewers also liked (7)

MULTITHREADING CONCEPT
MULTITHREADING CONCEPTMULTITHREADING CONCEPT
MULTITHREADING CONCEPT
 
Multithreaded processors ppt
Multithreaded processors pptMultithreaded processors ppt
Multithreaded processors ppt
 
FIne Grain Multithreading
FIne Grain MultithreadingFIne Grain Multithreading
FIne Grain Multithreading
 
Ch5: Threads (Operating System)
Ch5: Threads (Operating System)Ch5: Threads (Operating System)
Ch5: Threads (Operating System)
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Chapter 2 - Operating System Structures
Chapter 2 - Operating System StructuresChapter 2 - Operating System Structures
Chapter 2 - Operating System Structures
 
Flynns classification
Flynns classificationFlynns classification
Flynns classification
 

Similar to Multithreading models.ppt

Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
shreesha16
 

Similar to Multithreading models.ppt (20)

Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 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
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading models
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
 
Thread
ThreadThread
Thread
 
Thread
ThreadThread
Thread
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
 
4 threads
4 threads4 threads
4 threads
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Lecture6
Lecture6Lecture6
Lecture6
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Pthread
PthreadPthread
Pthread
 
Threads
ThreadsThreads
Threads
 
threads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptxthreads-ppfldkgsh;reghuiregiuhrughet.pptx
threads-ppfldkgsh;reghuiregiuhrughet.pptx
 
thread os.pptx
thread os.pptxthread os.pptx
thread os.pptx
 
OS Thr schd.ppt
OS Thr schd.pptOS Thr schd.ppt
OS Thr schd.ppt
 

More from Luis Goldster

More from Luis Goldster (20)

Ruby on rails evaluation
Ruby on rails evaluationRuby on rails evaluation
Ruby on rails evaluation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Lisp and scheme i
Lisp and scheme iLisp and scheme i
Lisp and scheme i
 
Ado.net & data persistence frameworks
Ado.net & data persistence frameworksAdo.net & data persistence frameworks
Ado.net & data persistence frameworks
 
Business analytics and data mining
Business analytics and data miningBusiness analytics and data mining
Business analytics and data mining
 
Big picture of data mining
Big picture of data miningBig picture of data mining
Big picture of data mining
 
Data mining and knowledge discovery
Data mining and knowledge discoveryData mining and knowledge discovery
Data mining and knowledge discovery
 
Cache recap
Cache recapCache recap
Cache recap
 
Directory based cache coherence
Directory based cache coherenceDirectory based cache coherence
Directory based cache coherence
 
Hardware managed cache
Hardware managed cacheHardware managed cache
Hardware managed cache
 
How analysis services caching works
How analysis services caching worksHow analysis services caching works
How analysis services caching works
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Optimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessorsOptimizing shared caches in chip multiprocessors
Optimizing shared caches in chip multiprocessors
 
Api crash
Api crashApi crash
Api crash
 
Object model
Object modelObject model
Object model
 
Abstraction file
Abstraction fileAbstraction file
Abstraction file
 
Object oriented analysis
Object oriented analysisObject oriented analysis
Object oriented analysis
 
Abstract class
Abstract classAbstract class
Abstract class
 
Concurrency with java
Concurrency with javaConcurrency with java
Concurrency with java
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 

Recently uploaded

+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@
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - 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...
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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 PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
+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...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Multithreading models.ppt

  • 2. Multithreading models • There are three dominant models for thread libraries, each with its own trade-offs – many threads on one LWP (many-to-one) – one thread per LWP (one-to-one) – many threads on many LWPs (many-to- many) • Similar models can apply on scheduling kernel threads to real CPUs
  • 3. Many-to-one • In this model, the library maps all threads to a single lightweight process • Advantages: – totally portable – easy to do with few systems dependencies • Disadvantages: – cannot take advantage of parallelism – may have to block for synchronous I/O – there is a clever technique for avoiding it • Mainly used in language systems, portable libraries
  • 4. One-to-one • In this model, the library maps each thread to a different lightweight process • Advantages: – can exploit parallelism, blocking system calls • Disadvantages: – thread creation involves LWP creation – each thread takes up kernel resources – limiting the number of total threads • Used in LinuxThreads and other systems where LWP creation is not too expensive
  • 5. Many-to-many • In this model, the library has two kinds of threads: bound and unbound – bound threads are mapped each to a single lightweight process – unbound threads may be mapped to the same LWP • Probably the best of both worlds • Used in the Solaris implementation of Pthreads (and several other Unix implementations)
  • 6. High-Level Program Structure Ideas • Boss/workers model • Pipeline model • Up-calls • Keeping shared information consistent using version stamps
  • 7. Thread Design Patterns Common ways of structuring programs using threads • Boss/workers model – boss gets assignments, dispatches tasks to workers – variants (thread pool, single thread per connection…) • Pipeline model – do some work, pass partial result to next thread • Up-calls – fast control flow transfer for layered systems • Version stamps – technique for keeping information consistent
  • 8. Boss/Workers Boss: Worker: forever { taskX(); get a request switch(request) case X: Fork (taskX) case Y: Fork (taskY) … } • Advantage: simplicity • Disadvantage: bound on number of workers, overheard of threads creation, contention if requests have interdependencies • Variants: fixed thread pool (aka workpile, workqueue), producer/consumer relationship, workers determine what needs to be performed…
  • 9. Pipeline • Each thread completes portion of a task, and passes results • like an assembly line or a processor pipeline • Advantages: trivial synchronization, simplicity • Disadvantages: limits degree of parallelism, throughput driven by slowest stage, handtuning needed
  • 10. Up-calls • Layered applications, e.g. network protocol stacks have top-down and bottom-up flows • Up-calls is a technique in which you structure layers so that they can expect calls from below • Thread pool of specialized threads in each layer – essentially an up-call pipeline per connection • Advantages: best when used with fast, synchronous control flow transfer mechanisms or program structuring tool • Disadvantages: programming becomes more complicated, synchronization required for top- down
  • 11. Version Stamps • (Not a programming structure idea but useful technique for any kind of distributed environment) • Maintain “version number” for shared data – keep local cached copy of data – check versions to determine if changed