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

More Related Content

What's hot (20)

Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
sangrampatil81
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
Satyamevjayte Haxor
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
Uday Sharma
 
Using data flow diagram
Using data flow diagramUsing data flow diagram
Using data flow diagram
Kiran Ajudiya
 
Component and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief OverviewComponent and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief Overview
Rajiv Kumar
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Pipelining and vector processing
Pipelining and vector processingPipelining and vector processing
Pipelining and vector processing
Kamal Acharya
 
Flynns classification
Flynns classificationFlynns classification
Flynns classification
Yasir Khan
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
Yong Heui Cho
 
Unified process model
Unified process modelUnified process model
Unified process model
RyndaMaala
 
Ddb 1.6-design issues
Ddb 1.6-design issuesDdb 1.6-design issues
Ddb 1.6-design issues
Esar Qasmi
 
Lect-4: UML diagrams - Unified Modeling Language - SPM
Lect-4: UML diagrams - Unified Modeling Language - SPMLect-4: UML diagrams - Unified Modeling Language - SPM
Lect-4: UML diagrams - Unified Modeling Language - SPM
Mubashir Ali
 
Multi Processors And Multi Computers
 Multi Processors And Multi Computers Multi Processors And Multi Computers
Multi Processors And Multi Computers
Nemwos
 
Requirement analysis and specification
Requirement analysis and specificationRequirement analysis and specification
Requirement analysis and specification
M.E. at GTU- PG School
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
advanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelismadvanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelism
Pankaj Kumar Jain
 
COCOMO Model By Dr. B. J. Mohite
COCOMO Model By Dr. B. J. MohiteCOCOMO Model By Dr. B. J. Mohite
COCOMO Model By Dr. B. J. Mohite
Zeal Education Society, Pune
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Muhammad Farooq
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
Muhammad Mansoor Ul Haq
 
Chpt7
Chpt7Chpt7
Chpt7
RohitKeshari
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
sangrampatil81
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
Uday Sharma
 
Using data flow diagram
Using data flow diagramUsing data flow diagram
Using data flow diagram
Kiran Ajudiya
 
Component and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief OverviewComponent and Deployment Diagram - Brief Overview
Component and Deployment Diagram - Brief Overview
Rajiv Kumar
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
Pipelining and vector processing
Pipelining and vector processingPipelining and vector processing
Pipelining and vector processing
Kamal Acharya
 
Flynns classification
Flynns classificationFlynns classification
Flynns classification
Yasir Khan
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
Yong Heui Cho
 
Unified process model
Unified process modelUnified process model
Unified process model
RyndaMaala
 
Ddb 1.6-design issues
Ddb 1.6-design issuesDdb 1.6-design issues
Ddb 1.6-design issues
Esar Qasmi
 
Lect-4: UML diagrams - Unified Modeling Language - SPM
Lect-4: UML diagrams - Unified Modeling Language - SPMLect-4: UML diagrams - Unified Modeling Language - SPM
Lect-4: UML diagrams - Unified Modeling Language - SPM
Mubashir Ali
 
Multi Processors And Multi Computers
 Multi Processors And Multi Computers Multi Processors And Multi Computers
Multi Processors And Multi Computers
Nemwos
 
Requirement analysis and specification
Requirement analysis and specificationRequirement analysis and specification
Requirement analysis and specification
M.E. at GTU- PG School
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
advanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelismadvanced computer architesture-conditions of parallelism
advanced computer architesture-conditions of parallelism
Pankaj Kumar Jain
 
Virtual memory and page replacement algorithm
Virtual memory and page replacement algorithmVirtual memory and page replacement algorithm
Virtual memory and page replacement algorithm
Muhammad Mansoor Ul Haq
 

Viewers also liked (10)

Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
Neeraj Kaushik
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlán
Pacman 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 event
UTS: University of Technology Sydney
 
Van outbound naar inbound marketing
Van outbound naar inbound marketingVan outbound naar inbound marketing
Van outbound naar inbound marketing
Robbert van der Vleuten
 
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
 
Fire Your Maid!
Fire Your Maid!Fire Your Maid!
Fire Your Maid!
Dallas Maids
 
Tv jenny
Tv jennyTv jenny
Tv jenny
corazoncitooliva
 
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
sinfome.com
 
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
UTS: University of Technology Sydney
 
Multithreading Presentation
Multithreading PresentationMultithreading Presentation
Multithreading Presentation
Neeraj Kaushik
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlán
Pacman 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 event
UTS: 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 017
sinfome.com
 
Ad

Similar to Multithreading models (20)

Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
Luis Goldster
 
Ch04 threads
Ch04 threadsCh04 threads
Ch04 threads
Nazir Ahmed
 
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
aakarshsiwani1
 
Thread
ThreadThread
Thread
sajidhuseyin
 
Thread
ThreadThread
Thread
Sajid Hussain
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
Welly Dian Astika
 
Operating system 20 threads
Operating system 20 threadsOperating system 20 threads
Operating system 20 threads
Vaibhav Khanna
 
Operating system 21 multithreading models
Operating system 21 multithreading modelsOperating system 21 multithreading models
Operating system 21 multithreading models
Vaibhav Khanna
 
Chapter04-OS.pptx........................
Chapter04-OS.pptx........................Chapter04-OS.pptx........................
Chapter04-OS.pptx........................
fakharsaleemraza
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
Kumbirai Junior Muzavazi
 
Threads.ppt
Threads.pptThreads.ppt
Threads.ppt
amadayshwan
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
shreesha16
 
Pthread
PthreadPthread
Pthread
Gopi Saiteja
 
Parallel processing
Parallel processingParallel processing
Parallel processing
Shivalik college of engineering
 
4 threads
4 threads4 threads
4 threads
Dr. Loganathan R
 
Threads lecture slides for operating systems
Threads lecture slides for operating systemsThreads lecture slides for operating systems
Threads lecture slides for operating systems
amirtarek401
 
Lecture6
Lecture6Lecture6
Lecture6
tt_aljobory
 
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
Sachin Gowda
 
W-9.pptx
W-9.pptxW-9.pptx
W-9.pptx
alianwarr
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
Harika Pudugosula
 
Ad

Recently uploaded (20)

U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 

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

Editor's Notes

  • #11: cannot keep holding lock when you call lower layer
  翻译: