CH 4
CH 4
Operating System Concepts – 10th Edition 4.1 Silberschatz, Galvin and Gagne ©2018
Objectives
In this lecture
Multithreaded models
Operating System Concepts – 10th Edition 4.2 Silberschatz, Galvin and Gagne ©2018
Motivation
Most modern applications are multithreaded
Operating System Concepts – 10th Edition 4.3 Silberschatz, Galvin and Gagne ©2018
Single and Multithreaded Processes
Operating System Concepts – 10th Edition 4.4 Silberschatz, Galvin and Gagne ©2018
Multithreaded Server Architecture
Operating System Concepts – 10th Edition 4.5 Silberschatz, Galvin and Gagne ©2018
Benefits
Responsiveness – may allow continued execution if part of
process is blocked, especially important for user interfaces
Operating System Concepts – 10th Edition 4.6 Silberschatz, Galvin and Gagne ©2018
Multicore Programming
The need for more computing performance, single-CPU
systems evolved into multi-CPU systems.
Operating System Concepts – 10th Edition 4.7 Silberschatz, Galvin and Gagne ©2018
Concurrency vs. Parallelism
Operating System Concepts – 10th Edition 4.8 Silberschatz, Galvin and Gagne ©2018
Multicore Programming challenges
Identifying tasks :This involves examining applications to find areas
that can be divided into separate, concurrent tasks.
Data splitting: The data accessed and manipulated by the tasks must
be divided to run on separate cores.
Operating System Concepts – 10th Edition 4.9 Silberschatz, Galvin and Gagne ©2018
Multicore Programming
Types of parallelism
Operating System Concepts – 10th Edition 4.10 Silberschatz, Galvin and Gagne ©2018
Data and Task Parallelism
Operating System Concepts – 10th Edition 4.11 Silberschatz, Galvin and Gagne ©2018
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
But does the law take into account contemporary multicore systems?
Operating System Concepts – 10th Edition 4.12 Silberschatz, Galvin and Gagne ©2018
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 Kernel threads
1. Allocate memory
2. Deallocate
3. Page swapping
Operating System Concepts – 10th Edition 4.13 Silberschatz, Galvin and Gagne ©2018
User and Kernel Threads
Operating System Concepts – 10th Edition 4.14 Silberschatz, Galvin and Gagne ©2018
Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Operating System Concepts – 10th Edition 4.15 Silberschatz, Galvin and Gagne ©2018
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 multicore system because
only one may be in kernel at a time
Few systems currently use this model
Examples:
• LINUX
Operating System Concepts – 10th Edition 4.16 Silberschatz, Galvin and Gagne ©2018
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
Operating System Concepts – 10th Edition 4.17 Silberschatz, Galvin and Gagne ©2018
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
Operating System Concepts – 10th Edition 4.18 Silberschatz, Galvin and Gagne ©2018
Two-level Model
Similar to M:M, except that it allows a user thread to be bound to
kernel thread
Operating System Concepts – 10th Edition 4.19 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 4.20 Silberschatz, Galvin and Gagne ©2018
(Next Lecture)Thread Libraries
Thread library provides programmer with API for creating and
managing threads
Two primary ways of implementing
• Library entirely in user space
• Kernel-level library supported by the OS
Operating System Concepts – 10th Edition 4.21 Silberschatz, Galvin and Gagne ©2018