CH 4 Threads
CH 4 Threads
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
Operating Systems
Thread
light weight is threds
• It composes of:
» Program counter
process can devide to number of threads
» Set of registers
local data saved in stack » Stack savind address temprory adres
» data section
» Other operating system resources
3
4.1.1 Motivation
• Fetch data
• Spell checking
• Answer a network request
■ Process creation is heavy-weight while thread
creation is light-weight
■ Can simplify code, increase efficiency
■ Kernels are generally multithreaded
Operating System Concepts – 9th Edition 4.4 Silberschatz, Galvin and Gagne ©2013
Operating Systems
5
Operating Systems
6
Single and Multithreaded Processes
stack and rigister can not be shared by threads
Figure 4.1
Operating System Concepts – 9th Edition 4.7 Silberschatz, Galvin and Gagne ©2013
Multithreaded Server Architecture
Operating System Concepts – 9th Edition 4.8 Silberschatz, Galvin and Gagne ©2013
Operating Systems
Applications
• Use by many software packages that run on modern desktop
PCs.
9
4.1.2 Benefits
when on of the task stoped all the other tasks will be stop
Operating System Concepts – 9th Edition 4.10 Silberschatz, Galvin and Gagne ©2013
4.2 Multicore Programming
Operating System Concepts – 9th Edition 4.11 Silberschatz, Galvin and Gagne ©2013
Multicore Programming (Cont.)
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
Operating System Concepts – 9th Edition 4.14 Silberschatz, Galvin and Gagne ©2013
Concurrency vs. Parallelism
run program in a single core
Figure 4.4
Operating System Concepts – 9th Edition 4.15 Silberschatz, Galvin and Gagne ©2013
Operating Systems
Concurrency
16
Operating Systems
Interleaving
P1
P2
P3
Time
Chapter 3
17
Operating Systems
• Multiprocessor system:
P1
P2
Chapter 3
P3
Time
18
Operating Systems
DOS – no concurrency)
__________________________________
* Stalling, W. Operating Systems: Internals and Design Principles (5th Edition). Prentice Hall. (2005)
19
Operating Systems
21
Operating Systems
Concurrent Programming
22
Operating Systems
Applications of Concurrent
Programming
A = 3 * B * C + 4 / (D + E) ** (F – G)
Uniprocessor
(Sequential Computation)
Chapter 3
23
Operating Systems
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
A = T1 + T2
Chapter 3
6
Uniprocessor
7 A (Sequential Computation)
24
Operating Systems
Multiprocessor
(Concurrent processing)
A = 3 * B * C + 4 / (D + E) ** (F – G)
Chapter 3
25
Operating Systems
1 2 3
A = 3 * B * C + 4 / (D + E) ** (F – G)
3 1 A = T4 + T1
Multiprocessor
4 1 A (Concurrent processing)
26
Operating Systems
EXAMPLE:
Screenshot from
MacBook Pro
Chapter 2
27
Chapter 2 Operating Systems
28
Chapter 2 Operating Systems
29
EXERCISE
From Silberchatz, Operating System Concepts
Chapter 4 Exercises
Operating System Concepts – 9th Edition 3.30 Silberschatz, Galvin and Gagne ©2013
End of Chapter 4
Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013