Professional Documents
Culture Documents
Chapter1 Introduction
Chapter1 Introduction
q That you mention their source, after all, I would like people to use my book!
q That you note that they are adapted from (or perhaps identical to)
my slides, and note my copyright of this material.
q Safety Property
m Nothing bad happens ever
m Example: mutual exclusion
q Liveness Property
m Something good happens eventually
m Example: progress
Alice Bob
leave note A leave note B
if (no note B) { if (no note A) {
if (no milk) {buy milk} if (no milk) {buy milk}
} }
remove note A remove note B
Alice Bob
leave note A leave note B
while (note B) {skip} if (no note A) {
if (no milk) {buy milk} if (no milk) {buy milk}
}
remove note A remove note B
A1 A2 B2 B1
Alice’s turn
A1 A2
X B2
X B2 A1 A2 B2 B1 A1 A2 B2 B1
B2 A2
X B2
X B1 A1 A2 B2 B1 A1 A2 B2 B1
Alice Bob
if B2 {leave A2} else {remove A2} if (no A2) {leave B2} else {remove B2}
leave A1 leave B1
while B1 and ((A2 and B2) or while A1 and ((A2 and no B2) or
(no A2 and no B2)) (no A2 and B2))
{skip} {skip}
if (no milk) {buy milk} if (no milk) {buy milk}
remove A1 MILK
remove note B1 MILK
Process A Process B
for i = 1 to 5 { x:=x+1 } for i = 1 to 5 { x:=x+1 }
A: 2 through 10 inclusive.
0 1 10 1
2
A B
4
3
5
2
0
1
A: 2,3,4,10,11,12,13,14.
1 2
Enemy
1 2
Enemy
Proof:
• Assume to the contrary that such an algorithm exits.
• Let P be an algorithm that solves with fewest # of
messages, when no message is lost.
• P should work even when the last messenger is captured.
• So P should work even if the last messenger is never sent.
• But this is a new algorithm with one less message.
• A contradiction.
è The (asynchronous) model is too weak.
P1 P2 P3
data structure
Blocking
P1 P2 P3
data structure
Non-blocking
P1 P2 P3
data structure
Barrier Synchronization
P1 P1 P1
P2 P2 P2
Barrier
Barrier
Barrier
P3 P3 P3
P4 P4 P4
time
begin a b c d e f
time
a+b+c a+b+c
end a a+b a+b+c a+b+c+d
+d+e +d+e+f
Chapter 1 Synchronization Algorithms and Concurrent Programming 35
Gadi Taubenfeld © 2014
Example: Sequential Prefix Sum
begin a b c d e f
a a+b c d e f
a a+b a+b+c d e f
time
a+b+c a+b+c
end a a+b a+b+c a+b+c+d
+d+e +d+e+f
Chapter 1 Synchronization Algorithms and Concurrent Programming 36
Gadi Taubenfeld © 2014
Example: Parallel Prefix Sum
begin a b c d e f
a+b+c a+b+c
end a a+b a+b+c a+b+c+d
+d+e +d+e+f
Chapter 1 Synchronization Algorithms and Concurrent Programming 37
Gadi Taubenfeld © 2014
Example: Parallel Prefix Sum
begin a b c d e f
barrier
a+b+c a+b+c
end a a+b a+b+c a+b+c+d
+d+e +d+e+f
Chapter 1 Synchronization Algorithms and Concurrent Programming 38
Gadi Taubenfeld © 2014
Chapter 9
Consensus
1 0 1 1 0 1 0
1 1 1 1 1 1 1
requirements:
q validity
q agreement
q termination
q Timing assumptions.
q Randomizations.
Message passing
m send/receive
m multi-cast
m broadcast
m network topology
This book
Parallel Concurrent/
Distributed
What is the relative power of these timing models?
C C M M
M M
q Hardware
m Processors
q Software
m Threads, processes
q Sometimes OK to confuse them,
sometimes not.
q Scheduler
User
space
Threads Threads
Kernel
space Kernel Kernel
admit exit
New Ready Running terminated
0 1 n -1 n
Scheduler
q First-come-first-served
schedules processes in the order they become ready.
q Shortest-job-first
schedule the process with the shortest time.
q Priority scheduling
schedule the process with the highest priority.
q Round robin –
each process is scheduled for a small number of time
units (milliseconds).
q Many other possibilities exist.
mutex
read/write
barrier test&set
readers&
swap
writers
consensus LL/SC
q Algorithms
q Upper and lower bounds
q Impossibility results
q Simulations & Implementations
remainder code
entry code
critical section
exit code
The problem is to design the entry and exit code in a way that
guarantees that the mutual exclusion and deadlock-freedom
properties are satisfied.
remainder
q Deadlock-freedom: If a process is trying
to enter its critical section, then some
process, not necessarily the same one, entry code
eventually enters its critical section.
critical
q Starvation-freedom: If a process is section
trying to enter its critical section, then
this process must eventually enter its
exit code
critical section.
entry code of A
-- Gadi