SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Overview of physical storage media
Overview of physical storage mediaOverview of physical storage media
Overview of physical storage media
Srinath Sri
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
myrajendra
 

Tendances (20)

FDDI
FDDIFDDI
FDDI
 
Chapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatzChapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatz
 
Operating Systems: Virtual Memory
Operating Systems: Virtual MemoryOperating Systems: Virtual Memory
Operating Systems: Virtual Memory
 
Overview of physical storage media
Overview of physical storage mediaOverview of physical storage media
Overview of physical storage media
 
Thrashing allocation frames.43
Thrashing allocation frames.43Thrashing allocation frames.43
Thrashing allocation frames.43
 
Distributed file system
Distributed file systemDistributed file system
Distributed file system
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Memory Organization
Memory OrganizationMemory Organization
Memory Organization
 
Dc ch10 : circuit switching and packet switching
Dc ch10 : circuit switching and packet switchingDc ch10 : circuit switching and packet switching
Dc ch10 : circuit switching and packet switching
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Cache memory
Cache memoryCache memory
Cache memory
 
Allocation of Frames & Thrashing
Allocation of Frames & ThrashingAllocation of Frames & Thrashing
Allocation of Frames & Thrashing
 
Pipelining
PipeliningPipelining
Pipelining
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Interleaved memory
Interleaved memoryInterleaved memory
Interleaved memory
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Kernel I/O subsystem
Kernel I/O subsystemKernel I/O subsystem
Kernel I/O subsystem
 
Flow control in Computer Network
Flow control in Computer NetworkFlow control in Computer Network
Flow control in Computer Network
 
program flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architectureprogram flow mechanisms, advanced computer architecture
program flow mechanisms, advanced computer architecture
 
Unit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - ThreadsUnit II - 2 - Operating System - Threads
Unit II - 2 - Operating System - Threads
 

En vedette

Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlán
Pacman Toxicore
 
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
 

En vedette (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
 

Similaire à Multithreading models

Multithreading models.ppt
Multithreading models.pptMultithreading models.ppt
Multithreading models.ppt
Luis Goldster
 
Module2 MultiThreads.ppt
Module2 MultiThreads.pptModule2 MultiThreads.ppt
Module2 MultiThreads.ppt
shreesha16
 

Similaire à 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)
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Dernier (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . 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

Notes de l'éditeur

  1. cannot keep holding lock when you call lower layer