




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Nathaniel Wesley Filardo
October 23, 2013
Outline
Introduction
Lock-Free Linked List Insertion
Lock-Free Linked List Deletion
Read-Copy-Update Mutual Exclusion
Lessons
Introduction Locks Might Take A While
Consider XCHG style locks which use while( xchg( &locked, LOCKED ) == LOCKED ) as their core operation.
(^) We could spend an unbounded amount of time here waiting...
(^) This implies we’ll have very high latency on contention...
(^) Locks by definition reduce parallelism.
Introduction Locks Might Take A While
That is, if N people are contending for a lock, N − 1 of them are just wasting time.
(^) It would be nice if they could all work at once...
... being careful not to step on each other when there was actually a problem.
Introduction Locks Can Be... Not So Bad?
Instead of a lock around a tree, we could have a tree with locks: ROOT
y y % %
(^) The protocol is lock the root, then (lock child & unlock parent) as you go down. (^) This kind of lock handoff is a very common design. Here every time a thread decides to go down one branch,
Introduction Locks Can Be... Not So Bad?
Trying to find node A.
Step 1: lock root pointer and top node
ROOT
y y % %
Introduction Locks Can Be... Not So Bad?
Trying to find node A.
Step 3: lock left child and unlock parent
ROOT
y y % %
Introduction
But let’s see what we can do without any locks at all.
Lock-Free Linked List Node
Node definition is simple: label t label void* next
(^) When drawing, we’ll use a shorthand: label t label = A void* next = &B
Insertion into a Linked List Without Locks Insertion Code
insertAfter(after, newlabel) { //lockList(); new = newNode(newlabel); prev = findLabel(after); new->next = prev->next; prev->next = new; //unlockList(); }
Insertion into a Linked List Without Locks Race trace in 410 notation
insertAfter(A,B) insertAfter(A,C) prev = &A B.next = A.next prev = &A C.next = A.next A.next = B A.next = C
Either of these assignments makes sense in isolation, but one of them will override the other!
Insertion into a Linked List Without Locks Precondition
One list, two items on it: A and D.
Insertion into a Linked List Without Locks Second step
' ' A &D //D NULL
88
(^) Two threads point their respective nodes C and B into list at D
B.next=&D C.next=&D
Insertion into a Linked List Without Locks One thread goes
' ' A &C
88
(^) Suppose the thread owning C completes its assignment first. A.next=&C