9.6-9.7: Optimistic and Lazy Synchronization
Jesper Pedersen Notander
Herlihy
Ch 9. Linked Lists: The Role of Locking
Optimistic Synchronization
head
tail
a
b
c
d
Node {
T value;
volatile Node next;
}
Absence from interference ⇒
b
Optimistic Synchronization
head
tail
a
b
c
d
e
predA
currA
#currA < #e
Optimistic Synchronization
head
tail
a
b
c
d
e
predA
currA
#currA < #e
Optimistic Synchronization
head
tail
a
b
c
d
e
predA
currA
#currA < #e
Optimistic Synchronization
head
tail
a
b
c
d
e
predA
currA
#currA < #e
Optimistic Synchronization
head
tail
a
b
d
e
predA
currA
c
Interference
Optimistic Synchronization
head
tail
a
b
d
e
predA
currA
c
Validation
predA .next == currA
Optimistic Synchronization
head
tail
a
b
d
predA
Validation
e
currA
c
CONFLICT ⇒ RESTART
predA .next == currA
Optimistic Synchronization
head
tail
a
b
d
predA
currA
c
head
tail
a
b
d
predA
currA
c
add(e)
remove(e)
e
Optimistic Synchronization
head
tail
a
b
d
predA
currA
c
head
tail
a
b
d
predA
currA
c
e
add(e)
remove(e)
Optimistic Summary
Lazy Synchronization
head
tail
a
b
c
d
Node {
boolean marked;
T value;
volatile Node next;
}
Every unmarked node is reachable!
Lazy Synchronization
a
b
e
c
d
!predA.marked &&
!currA.marked &&
predA.next == currA
Validation
head
tail
predA
currA
Lazy Synchronization
head
tail
a
b
e
predA
currA
c
d
CONFLICT ⇒ RESTART
!predA.marked &&
!currA.marked &&
predA.next == currA
Validation
Optimistic Synchronization
currA
c
head
tail
a
b
d
predA
Physical removal
Logical removal (mark)
remove(e)
Lazy Synchronization
Thank
You
Exercises
Ex 1) Show that the add() method in the optimistic algorithm only need to lock either pred or curr?
Ex 2) Would the lazy algorithm work if we set the next field to null, instead of using a boolean flag?