Chapter 4: Threads: Silberschatz, Galvin and Gagne ©2013 Operating System Concepts - 9 Edition
Chapter 4: Threads: Silberschatz, Galvin and Gagne ©2013 Operating System Concepts - 9 Edition
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013
Chapter 4: Threads
■ 1.1 Overview
■ 1.2 Multicore Programming
OBJECTIVES
■ To introduce the notion of a thread—a fundamental unit of
CPU utilization that forms the basis of multithreaded computer
systems
Operating System Concepts – 9th Edition 4.2 Silberschatz, Galvin and Gagne ©2013
Thread
• Thread: a basic unit of CPU utilization;
• It composes of:
» Program counter
» Set of registers
» Stack
Figure 4.1
Operating System Concepts – 9th Edition 4.7 Silberschatz, Galvin and Gagne ©2013
Multithreaded Server Architecture
Figure 4.2
Operating System Concepts – 9th Edition 4.8 Silberschatz, Galvin and Gagne ©2013
Applications
• Use by many software packages that run on modern desktop
PCs.
Operating System Concepts – 9th Edition 4.10 Silberschatz, Galvin and Gagne ©2013
4.2 Multicore Programming
■ Multi-CPU systems. Multiple CPUs are placed in
the computer to provide more computing
performance.
■ Multicore systems. Multiple computing cores are placed on
a single processing chip where each core appears as a
separate CPU to the operating system
■ Multithreaded programming provides a mechanism for more
efficient use of these multiple computing cores and improved
concurrency.
■ Consider an application with four threads.
On a system with a single computing core, concurrency
means that the execution of the threads will be interleaved
over time.
On a system with multiple cores, however, concurrency
means that some threads can run in parallel, because the
Operating System Concepts – 9th Edition 4.11 Silberschatz, Galvin and Gagne ©2013
Multicore Programming (Cont.)
■ There is a fine but clear distinction between concurrency
and parallelism.
Operating System Concepts – 9th Edition 4.12 Silberschatz, Galvin and Gagne ©2013
Multicore Programming (Cont.)
■ 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
Operating System Concepts – 9th Edition 4.13 Silberschatz, Galvin and Gagne ©2013
Multicore Programming
■ Multicore or multiprocessor systems are placing 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
concurrency
Operating System Concepts – 9th Edition 4.14 Silberschatz, Galvin and Gagne ©2013
Concurrency vs. Parallelism
■ Concurrent execution on single-core system:
Figure 4.4
Operating System Concepts – 9th Edition 4.15 Silberschatz, Galvin and Gagne ©2013
Concurrency
• In a uniprocessor multiprogramming system:
P1
P2
P3
Tim
e
• Multiprocessor system:
P1
Chapter 3
P2
P3
• Concurrency arises / occurs in three different contexts*:
* Stalling, W. Operating Systems: Internals and Design Principles (5th Edition). Prentice Hall. (2005)
• Interleaving and overlapping execution of
processes can be viewed as examples of
concurrent processing;
Need control synchronization and data access
synchronization (Chapter 6).
– Global variables;
– Shared files or data bases;
Chapter 3
Uniprocessor
(Sequential Computation)
A = 3 * B * C + 4 / (D + E) ** (F – G)
Steps Operation
1 A = 3 * B * C + 4 / (D + E) ** T1
2 A = 3 * B * C + 4 / T2 ** T1
3 A = 3 * B * C + 4 / T1
4 A = 3 * B * C + T2
5 A = T1 * C + T2
6 A = T1 + T2
A Uniprocessor
7 (Sequential Computatio n)
Multiprocessor (Concurrent
processing)
Chapter 3 A = 3 * B * C + 4 / (D + E) ** (F – G)
1 2 3
A = 3 * B * C + 4 / (D + E) ** (F – G)
3 1 A = T4 + T1
Multiprocessor
4 1 A (Concurrent processing)
EXAMPLE:
Screenshot from
MacBook Pro
End of Chapter 4
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013