Lecture5 (Threads)
Lecture5 (Threads)
Operating System Concepts – 10th Edition 4.3 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.4 Silberschatz, Galvin and Gagne ©2018
Benefits Multicore Programming
Multicore or multiprocessor systems putting pressure on
Responsiveness – may allow continued execution if part of programmers, challenges include:
process is blocked, especially important for user interfaces
Dividing activities
Resource Sharing – threads share resources of process,
easier than shared memory or message passing Balance
Economy – cheaper than process creation, thread switching Data splitting
lower overhead than context switching Data dependency
Scalability – process can take advantage of multicore Testing and debugging
architectures Parallelism implies a system can perform more than one task
simultaneously
Concurrency supports more than one task making progress
Single processor / core, scheduler providing concurrency
Operating System Concepts – 10th Edition 4.5 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.6 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 4.7 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.8 Silberschatz, Galvin and Gagne ©2018
Data and Task Parallelism 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
That is, if application is 75% parallel / 25% serial, moving from 1 to 2 cores
results in speedup of 1.6 times
As N approaches infinity, speedup approaches 1 / S
But does the law take into account contemporary multicore systems?
Operating System Concepts – 10th Edition 4.9 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.10 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 4.11 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.12 Silberschatz, Galvin and Gagne ©2018
User and Kernel Threads Multithreading Models
Many-to-One
One-to-One
Many-to-Many
Operating System Concepts – 10th Edition 4.13 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.14 Silberschatz, Galvin and Gagne ©2018
Many-to-One One-to-One
Many user-level threads mapped to single kernel thread Each user-level thread maps to kernel thread
One thread blocking causes all to block Creating a user-level thread creates a kernel thread
Multiple threads may not run in parallel on multicore system More concurrency than many-to-one
because only one may be in kernel at a time Number of threads per process sometimes restricted due to
Few systems currently use this model overhead
Examples: Examples
Solaris Green Threads Windows
GNU Portable Threads Linux
Operating System Concepts – 10th Edition 4.15 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.16 Silberschatz, Galvin and Gagne ©2018
Many-to-Many Model Two-level Model
Allows many user level threads to be mapped to many kernel threads Similar to M:M, except that it allows a user thread to be
Allows the operating system to create a sufficient number of kernel bound to kernel thread
threads
Windows with the ThreadFiber package
Otherwise not very common
Operating System Concepts – 10th Edition 4.17 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.18 Silberschatz, Galvin and Gagne ©2018
Thread library provides programmer with API for creating May be provided either as user-level or kernel-level
and managing threads A POSIX standard (IEEE 1003.1c) API for thread creation
Two primary ways of implementing and synchronization
Library entirely in user space Specification, not implementation
Kernel-level library supported by the OS API specifies behavior of the thread library, implementation
is up to development of the library
Common in UNIX operating systems (Linux & Mac OS X)
Operating System Concepts – 10th Edition 4.19 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.20 Silberschatz, Galvin and Gagne ©2018
Implicit Threading Thread Pools
Create a number of threads in a pool where they await work
Growing in popularity as numbers of threads increase, Advantages:
program correctness more difficult with explicit threads Usually slightly faster to service a request with an existing thread than
create a new thread
Creation and management of threads done by compilers
and run-time libraries rather than programmers Allows the number of threads in the application(s) to be bound to the
size of the pool
Five methods explored Separating task to be performed from mechanics of creating task
Thread Pools allows different strategies for running task
i.e.Tasks could be scheduled to run periodically
Fork-Join
Windows API supports thread pools:
OpenMP
Grand Central Dispatch
Intel Threading Building Blocks
Operating System Concepts – 10th Edition 4.21 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.22 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 4.23 Silberschatz, Galvin and Gagne ©2018 Operating System Concepts – 10th Edition 4.24 Silberschatz, Galvin and Gagne ©2018