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

More Related Content

What's hot

Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
Sunita Sahu
 
Multivector and multiprocessor
Multivector and multiprocessorMultivector and multiprocessor
Multivector and multiprocessorKishan Panara
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
Anas Ebrahim
 
Reference model of real time system
Reference model of real time systemReference model of real time system
Reference model of real time system
Kamal Acharya
 
Threads
ThreadsThreads
Threads
Shivam Singh
 
Introduction to Parallel Computing
Introduction to Parallel ComputingIntroduction to Parallel Computing
Introduction to Parallel Computing
Akhila Prabhakaran
 
Evolutionary models
Evolutionary modelsEvolutionary models
Evolutionary models
Pihu Goel
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
Akhila Prabhakaran
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
BaliThorat1
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
MNM Jain Engineering College
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
SHATHAN
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
Multiprocessor Scheduling
Multiprocessor SchedulingMultiprocessor Scheduling
Multiprocessor Scheduling
Khadija Saleem
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria myrajendra
 
Multilevel queue scheduling
Multilevel queue schedulingMultilevel queue scheduling
Multilevel queue scheduling
AditiPawaskar5
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
meet darji
 
Demand paging
Demand pagingDemand paging
Demand paging
SwaroopSorte
 

What's hot (20)

Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Multivector and multiprocessor
Multivector and multiprocessorMultivector and multiprocessor
Multivector and multiprocessor
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Reference model of real time system
Reference model of real time systemReference model of real time system
Reference model of real time system
 
Threads
ThreadsThreads
Threads
 
Introduction to Parallel Computing
Introduction to Parallel ComputingIntroduction to Parallel Computing
Introduction to Parallel Computing
 
Evolutionary models
Evolutionary modelsEvolutionary models
Evolutionary models
 
Introduction to OpenMP
Introduction to OpenMPIntroduction to OpenMP
Introduction to OpenMP
 
Shared memory
Shared memoryShared memory
Shared memory
 
Semaphores
SemaphoresSemaphores
Semaphores
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Distributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithmsDistributed Mutual exclusion algorithms
Distributed Mutual exclusion algorithms
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Multiprocessor Scheduling
Multiprocessor SchedulingMultiprocessor Scheduling
Multiprocessor Scheduling
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Multilevel queue scheduling
Multilevel queue schedulingMultilevel queue scheduling
Multilevel queue scheduling
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
Demand paging
Demand pagingDemand paging
Demand paging
 

Viewers also liked

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á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 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
 
Tv jenny
Tv jennyTv jenny
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
 

Viewers also liked (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 to Multithreading models

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
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
 
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
 
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
 
Coding For Cores - C# Way
Coding For Cores - C# WayCoding For Cores - C# Way
Coding For Cores - C# Way
Bishnu 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 to 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)
 

Recently uploaded

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

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

  1. cannot keep holding lock when you call lower layer