SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente (20)

Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Hardware and Software parallelism
Hardware and Software parallelismHardware and Software parallelism
Hardware and Software parallelism
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Compilers
CompilersCompilers
Compilers
 
Os presentation
Os presentationOs presentation
Os presentation
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Parallelism
ParallelismParallelism
Parallelism
 
Array Processor
Array ProcessorArray Processor
Array Processor
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Ch12 microprocessor interrupts
Ch12 microprocessor interruptsCh12 microprocessor interrupts
Ch12 microprocessor interrupts
 
Memory management
Memory managementMemory management
Memory management
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Microprogram Control
Microprogram Control Microprogram Control
Microprogram Control
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 

Destacado

Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading PresentationNeeraj Kaushik
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlánPacman Toxicore
 
Big Change: sustainable healthcare for the 21st century - Photos from the event
Big Change: sustainable healthcare for the 21st century - Photos from the eventBig Change: sustainable healthcare for the 21st century - Photos from the event
Big Change: sustainable healthcare for the 21st century - Photos from the eventUTS: University of Technology Sydney
 
Final Year Project Training At Cresco Solution.
Final Year Project Training At Cresco Solution. Final Year Project Training At Cresco Solution.
Final Year Project Training At Cresco Solution. Jalpa Rajpurohit
 
Shirdi Shri Sai Baba Ji - Real Story 017
Shirdi Shri Sai Baba Ji - Real Story 017Shirdi Shri Sai Baba Ji - Real Story 017
Shirdi Shri Sai Baba Ji - Real Story 017sinfome.com
 

Destacado (10)

Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlán
 
Big Change: sustainable healthcare for the 21st century - Photos from the event
Big Change: sustainable healthcare for the 21st century - Photos from the eventBig Change: sustainable healthcare for the 21st century - Photos from the event
Big Change: sustainable healthcare for the 21st century - Photos from the event
 
Van outbound naar inbound marketing
Van outbound naar inbound marketingVan outbound naar inbound marketing
Van outbound naar inbound marketing
 
Final Year Project Training At Cresco Solution.
Final Year Project Training At Cresco Solution. Final Year Project Training At Cresco Solution.
Final Year Project Training At Cresco Solution.
 
Fire Your Maid!
Fire Your Maid!Fire Your Maid!
Fire Your Maid!
 
Tv jenny
Tv jennyTv jenny
Tv jenny
 
Worl Wonders Proyect
Worl Wonders ProyectWorl Wonders Proyect
Worl Wonders Proyect
 
Shirdi Shri Sai Baba Ji - Real Story 017
Shirdi Shri Sai Baba Ji - Real Story 017Shirdi Shri Sai Baba Ji - Real Story 017
Shirdi Shri Sai Baba Ji - Real Story 017
 
World Health Day 2014 - Breakfast and Panel Discusssion
World Health Day 2014 - Breakfast and Panel DiscusssionWorld Health Day 2014 - Breakfast and Panel Discusssion
World Health Day 2014 - Breakfast and Panel Discusssion
 

Similar a Multithreading models

Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.pptLuis Goldster
 
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.pptaakarshsiwani1
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threadsVaibhav Khanna
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading modelsVaibhav Khanna
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.pptshreesha16
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingSachin Gowda
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfHarika Pudugosula
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# WayBishnu Rawal
 
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__
 

Similar a Multithreading models (20)

Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
 
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
 
Thread
ThreadThread
Thread
 
Thread
ThreadThread
Thread
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading models
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
 
Pthread
PthreadPthread
Pthread
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
4 threads
4 threads4 threads
4 threads
 
Lecture6
Lecture6Lecture6
Lecture6
 
VTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computingVTU 6th Sem Elective CSE - Module 3 cloud computing
VTU 6th Sem Elective CSE - Module 3 cloud computing
 
W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
 
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)
 

Último

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Último (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

Multithreading models

  • 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

Notas del editor

  1. cannot keep holding lock when you call lower layer