CS4231 Parallel and Distributed Algorithms
CS4231 Parallel and Distributed Algorithms
CS4231 Parallel and Distributed Algorithms
AY 2006/2007 Semester 2
Lecture 3 (26/01/2006)
Instructor: Haifeng YU
Review of Last Lecture
Why do we need synchronization primitives
Busy waiting waste CPU
But synchronization primitives need OS support
Semaphore:
Using semaphore to solve dining philosophers problem
Avoiding deadlocks
Monitor:
Easier to use than semaphores / more popular
Two kinds of monitors
Using monitor to solve producer-consumer and reader-writer
problem
Sequential consistency
Linearizability
concurrent:
inv(p, read, X) inv(q, write, X, 1) resp(p, read, X, 0) resp(q, write, X, OK)
write(x,1) ok()
P
read(x) ok(2) ?
Q
write(x,1) o1 ok()
P
read(x) ok(1)
Q
o2 read(x) ok(0)
R
o3
Another interesting example
H | x is sequentially consistent:
operations on o1
operations on o2
operations on o3
Lemma: The resulting directed graph does not have a cycle (we
prove this later)
Any topological sorting of the above graph gives us a legal
serial history S, and the edges in the graph is a subset of the
total order induced by S – Theorem proved
operations on obj1
operations on obj2
operations on obj3
operations on obj1
operations on obj2
operations on obj3
operations on obj1
operations on obj2
operations on obj3
Impossible to have
Edges due to some object x, followed by
Edges due to some object y
operations on obj1
operations on obj2
operations on obj3
write read
write(1)
P Sequentially consistent
read(0) but not regular
Q
write(1)
P Regular but not
read(1) read(0) sequentially consistent
Q
Sequential consistency
Linearizability
Linearizability is a local property
Read Chapter 7