cisc 3320 c12a: threads and multithread model · 2020-05-13 · core (2 worker processes or 2...
TRANSCRIPT
![Page 1: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/1.jpg)
CISC 3320
C12a: Threads and Multithread Model
Hui Chen
Department of Computer & Information Science
CUNY Brooklyn College
3/6/2019 1CUNY | Brooklyn College
![Page 2: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/2.jpg)
Acknowledgement
• These slides are a revision of the slides provided by the authors of the textbook
3/6/2019 CUNY | Brooklyn College 2
![Page 3: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/3.jpg)
Outline
• Overview
• Multicore Programming
• Multithreading Models
• Thread Libraries
• Implicit Threading
• Threading Issues
• Operating System Examples
3/6/2019 CUNY | Brooklyn College 3
![Page 4: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/4.jpg)
Recap: Multiprogramming and Multiprocess Architecture• OS loads multiple programs and execute
them concurrently
• Notation of process
• Independent processes
• Cooperating processes
3/6/2019 CUNY | Brooklyn College 4
![Page 5: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/5.jpg)
Recap: MultiprocessArchitecture• Example applications
• Chrome Web browser
• The instructor’s Monte Carlo simulation application
3/6/2019 CUNY | Brooklyn College 5
![Page 6: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/6.jpg)
Recap: New Renderer Created for Each Website Opened
3/6/2019 CUNY | Brooklyn College 6
![Page 7: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/7.jpg)
Recap: Computation Speed-up by Cooperating Processes• Estimate using a Monte Carlo simulation
• What if a machine has multiple CPU cores? Can we take advantage of it?
3/6/2019 CUNY | Brooklyn College 7
![Page 8: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/8.jpg)
Motivation for Threads
• Multiprocess architecture
• Cost (or overhead)
• Process creation and switching are heavy-weight
• Project 2: quantifying process context switching cost
• Communication
• Inter-process communications (slow or complex)
3/6/2019 CUNY | Brooklyn College 8
![Page 9: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/9.jpg)
Introducing Multithreaded Processes
3/6/2019 CUNY | Brooklyn College 9
![Page 10: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/10.jpg)
Example: Observing Threads and Threads Switching• We can write an application to run multiple
functions concurrently, and each becomes thread
• Example: implement it in UNIX systems in user mode
• Understand concept of context
• Understand context switching
• We will examine this example closer again when we discuss CPU scheduling
3/6/2019 CUNY | Brooklyn College 10
![Page 11: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/11.jpg)
Questions?
• Some motivations for threads
• Concepts of threads and comparison with process
3/6/2019 CUNY | Brooklyn College 11
![Page 12: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/12.jpg)
Benefits of Multithread Architecture• Improving responsiveness
• Easing resource sharing
• Can be made more economic (less overhead)
• Can be more scalable (to multicore architecture)
3/6/2019 CUNY | Brooklyn College 12
![Page 13: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/13.jpg)
Multiprocess and Multithread Architectures• Benefits of threads when compared to
multiprocess architecture
3/6/2019 CUNY | Brooklyn College 13
![Page 14: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/14.jpg)
Examples of Multiprocess and Multithread Architectures
3/6/2019 CUNY | Brooklyn College 14
![Page 15: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/15.jpg)
Multithread Architecture: Responsiveness• May allow continued execution if part of
process is blocked
• Especially important for user interfaces
• Example: let’s look at even-programming for graphical user interface
3/6/2019 CUNY | Brooklyn College 15
![Page 16: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/16.jpg)
Event-Driven Programming for Graphical User Interface• The main body of the program is an event loop (in pseudo code)
do {
e = getNextEvent()
processEvent(e)
} while (e != EXIT_EVENT)
• This event loop typically implemented by the platform, and runs in a thread
• The events are in a queue called event queue
• Users write event handler routines (user’s programs) to process events
• processEvent in the above will invoke your event handler routines
• Event thus drives user’s programs
3/6/2019 CUNY | Brooklyn College 16
![Page 17: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/17.jpg)
Event-Loop Runs in a Thread
• Event loop
do {
e = getNextEvent()
processEvent(e)
} while (e != EXIT_EVENT)
• What happens if the processEvent method takes a long time to complete?
• Also consider the events are in a queue called event queue (capacity?)
3/6/2019 CUNY | Brooklyn College 17
![Page 18: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/18.jpg)
Example Application: The Estimator as a GUI application• Two versions
• Without thread and with thread (for estimation)
• Observe how responsive the application becomes when we increase the random points generated.
3/6/2019 CUNY | Brooklyn College 18
![Page 19: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/19.jpg)
Recap: Multithread Architecture: Responsiveness• May allow continued execution if part of
process is blocked
• Especially important for user interfaces
• Example: let’s look at even-programming for graphical user interface
3/6/2019 CUNY | Brooklyn College 19
Expected to be completed very quickly (a fraction of a second)
• Event loopdo {
e = getNextEvent()processEvent(e)
} while (e != EXIT_EVENT)
![Page 20: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/20.jpg)
Questions?
• Improve application responsiveness via a multithreaded architecture
3/6/2019 CUNY | Brooklyn College 20
![Page 21: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/21.jpg)
Benefits of Multithread Architecture: Resource Sharing• Threads share resources of process, easier
than shared memory or message passing
3/6/2019 CUNY | Brooklyn College 21
![Page 22: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/22.jpg)
Benefits of Multithread Architecture: Scalability• A process can take advantage of multicore
architectures using multiple threads
3/6/2019 CUNY | Brooklyn College 22
![Page 23: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/23.jpg)
Example: The Multiprocess or Multithread Estimator• Estimate using a Monte Carlo simulation
• What if a machine has multiple CPU cores? Can we take advantage of it?
• Case 1: we try 80000000 trials on 1 CPU core (1 worker process or 1 worker thread)
• Case 2: we try 80000000/2 trials for each process on 2 CPU core (2 worker processes or 2 worker threads)
• Case 3: we try 80000000/4 trials for each process on 4 CPU core (4 worker processes or 2 worker threads)
• Worker processes need to send master process the results (in this example, via a named pipe)
• Worker threads write results to the heap or the global variables
3/6/2019 CUNY | Brooklyn College 23
![Page 24: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/24.jpg)
Example: The Multiprocess or Multithread Estimator• Your observations?
• Which methods of sharing data is more convenient for programmers?
• Do you observe computation speed up?
• Based on our experiment, are threads always light-weight?
3/6/2019 CUNY | Brooklyn College 24
![Page 25: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/25.jpg)
Questions?
• Multiprocess architecture vs. multithread architecture
• Resource sharing?
• Scalability?
3/6/2019 CUNY | Brooklyn College 25
![Page 26: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/26.jpg)
Benefits of Multithread Architecture: Economy• Threads creation is generally cheaper than
process creation
• Thread context switching is generally of lower overhead than process context switching
• Project 2: quantifying cost of context switch
3/6/2019 CUNY | Brooklyn College 26
![Page 27: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/27.jpg)
Questions?• Benefits of Multithread Architecture
• Responsiveness
• may allow continued execution if part of process is blocked, especially important for user interfaces
• Resource Sharing
• threads share resources of process, easier than shared memory or message passing
• Economy
• cheaper than process creation, thread switching lower overhead than context switching
• Scalability
• process can take advantage of multicore architectures
3/6/2019 CUNY | Brooklyn College 27
![Page 28: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/28.jpg)
Multicore Programming• Multicore or multiprocessor systems putting pressure on
programmers, challenges include:
• Dividing activities
• Balance
• Data splitting
• Data dependency
• Testing and debugging
• Parallelism implies a system can perform more than one task simultaneously
• Concurrency supports more than one task making progress
• Single processor / core, scheduler providing concurrency3/6/2019 CUNY | Brooklyn College 28
![Page 29: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/29.jpg)
Concurrency vs. Parallelism
• Concurrent execution on single-core system
• Parallelism on a multi-core system
3/6/2019 CUNY | Brooklyn College 29
![Page 30: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/30.jpg)
Multicore Programming
• Types of parallelism
• Data parallelism – distributes subsets of the same data across multiple cores, same operation on each
• Task parallelism – distributing threads across cores, each thread performing unique operation
3/6/2019 CUNY | Brooklyn College 30
![Page 31: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/31.jpg)
Data and Task Parallelism
3/6/2019 CUNY | Brooklyn College 31
![Page 32: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/32.jpg)
Performance Gain via Parallelism
• How much do we gain in this example?
• Is this example data parallelism or task parallelism?
• If it is data parallelism, can you revise this example to exhibit task parallelism or vice versus?
• How much can we gain from parallelism?
3/6/2019 CUNY | Brooklyn College 32
![Page 33: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/33.jpg)
Amdahl’s Law
• Identifies performance gains from adding additional cores to an application that has both serial and parallel components
• S is serial portion
• N processing cores
3/6/2019 CUNY | Brooklyn College 33
![Page 34: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/34.jpg)
Amdahl’s Law: Example
• That is, if application is 75% parallel / 25% serial
• 1/(0.25 + 0.75/2) = 1.6
• moving from 1 to 2 cores results in speedup of 1.6 times
• As N approaches infinity, speedup approaches 1 / S
• lim𝑁→∞
1
𝑆+1−𝑆
𝑁
=1
𝑆
• Serial portion of an application has disproportionate effect on performance gained by adding additional cores
3/6/2019 CUNY | Brooklyn College 34
![Page 35: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/35.jpg)
3/6/2019 CUNY | Brooklyn College 35
![Page 36: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/36.jpg)
Questions?
• Amdahl’s Law
• Does the law take into account contemporary multicore systems?
• Recall: the two versions of the estimator
3/6/2019 CUNY | Brooklyn College 36
![Page 37: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/37.jpg)
User Threads and Kernel Threads• User threads - management done by user-level threads library
• Three primary thread libraries:
• POSIX Pthreads
• Windows threads
• Java threads
• Kernel threads - Supported by the Kernel
• Examples – virtually all general purpose operating systems, including:
• Windows
• Linux
• Mac OS X
• iOS
• Android
3/6/2019 CUNY | Brooklyn College 37
![Page 38: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/38.jpg)
Threads In User or Kernel Space• In the user space, or in the kernel
3/6/2019 CUNY | Brooklyn College 38
User- and kernel-level threads [Figure 2-16 in Tanenbaum & Bos, 2014]
![Page 39: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/39.jpg)
Efficiency and Concurrency
• Kernel threads are more expensive to create
• Can support multiple processors
• User threads can be blocked by the process
• Less concurrency, in particular, on multiprocessor/multicore systems
• Recall: the user mode two thread program discussed at the beginning
3/6/2019 CUNY | Brooklyn College 39
![Page 40: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/40.jpg)
User and Kernel Threads
3/6/2019 CUNY | Brooklyn College 40
![Page 41: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/41.jpg)
Multithreading Models
• Many-to-One
• One-to-One
• Many-to-Many
3/6/2019 CUNY | Brooklyn College 41
![Page 42: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/42.jpg)
Many-to-One
• Many user-level threads mapped to single kernel thread
• One thread blocking causes all to block
• Multiple threads may not run in parallel on muticore system because only one may be in kernel at a time
• Few systems currently use this model
• Examples:
• Solaris Green Threads
• GNU Portable Threads
3/6/2019 CUNY | Brooklyn College 42
![Page 43: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/43.jpg)
Many-to-One
3/6/2019 CUNY | Brooklyn College 43
![Page 44: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/44.jpg)
One-to-One
• Each user-level thread maps to kernel thread
• Creating a user-level thread creates a kernel thread
• More concurrency than many-to-one
• Number of threads per process sometimes restricted due to overhead
• Examples
• Windows
• Linux
3/6/2019 CUNY | Brooklyn College 44
![Page 45: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/45.jpg)
One-to-One
3/6/2019 CUNY | Brooklyn College 45
![Page 46: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/46.jpg)
Many-to-Many Model
• Allows many user level threads to be mapped to many kernel threads
• Allows the operating system to create a sufficient number of kernel threads
• Windows with the ThreadFiber package
• Otherwise not very common
3/6/2019 CUNY | Brooklyn College 46
![Page 47: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/47.jpg)
3/6/2019 CUNY | Brooklyn College 47
![Page 48: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/48.jpg)
Two-level Model
• Similar to M:M, except that it allows a user thread to be bound to kernel thread
3/6/2019 CUNY | Brooklyn College 48
![Page 49: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/49.jpg)
3/6/2019 CUNY | Brooklyn College 49
![Page 50: CISC 3320 C12a: Threads and Multithread Model · 2020-05-13 · core (2 worker processes or 2 worker threads) •Case 3: we try 80000000/4 trials for each process on 4 CPU core (4](https://reader034.vdocuments.us/reader034/viewer/2022052611/5f0813b57e708231d420380d/html5/thumbnails/50.jpg)
Questions?
• Concept of thread
• Parallelism and concurrency
• Data and task parallelism
• Amdahl’s Law
• Multithread model
3/6/2019 CUNY | Brooklyn College 50