Upload
dale-banks
View
229
Download
0
Embed Size (px)
Citation preview
1
Lock-Free Linked Lists Using Lock-Free Linked Lists Using Compare-and-SwapCompare-and-Swap
by John Valois
Speaker’s Name:
Talk Title:
Larry BushLarry Bush
5
bool Compare&Swap ( Type * x, Type old, Type new) {
// BEGIN ATOMIC if *x != old {
• *x = new;
• return TRUE; } else {
• return FALSE } // END ATOMIC
}
Compare&Swap Compare&Swap Synchronization Synchronization PrimitivePrimitive
6
Why is this important ?Why is this important ?
Avoids Mutual Exclusion Problems
Convoying
Deadlock
Priority Inversion Busy Waiting
Blocking
7
Universal methods are not efficient (Herlihy).
Massalin and Pu’s method required the uncommon double word Compare&Swap.
Limitations of current Limitations of current implementationsimplementations
8
As quick as spin locks
Without blocking or busy waiting (wait free)
Benefits of new Benefits of new implementationsimplementations
25
Conclusion Conclusion Allows concurrent operations
Good for:parallel processingdistributed memory
Should be used everywhere
29
Aux NodesAux Nodes
Insertion of new cells takes place between an auxiliary node and an existing regular cell.
Chains of auxilary nodes are allowed. An auxilary node is not required to have a real cell node before and after it.
31
Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree.
ContributionsContributions
32
Why do you say this is lock-free if Why do you say this is lock-free if it uses a mutual exclusion it uses a mutual exclusion
primitive?primitive?Limited to atomic actions provided by the
hardware.Only when swinging pointers. Allows simultaneous traversal, insertion
and deletion.
Lamport (made the distinction)Massalin and Pu (coined the term)
33
ptr = find ptr of interest
repeat old = Read( ptr ); new = compute new pointer value r = Compare&Swap(ptr, old, new)
until ( r = TRUE )}
Swinging the PointerSwinging the Pointer
34
q = new cell
Repeat
r = SafeRead ( p -> next ) Write ( q -> next, r )
until Compare&Swap( p -> next, r, q )
Insert ( p, x )Insert ( p, x )
35
node * target; // -> data
node * pre_aux; // -> preceding auxiliary node
node * pre_cell; // -> previous cell
struct Cursor {struct Cursor {
};};
36
// Updates pointers in the cursor so that it becomes valid.
// removes double aux_node.
Update(cursor c) {Update(cursor c) {
};};
37
c.pre_cell = next // deletes cellback_link = c->pre_celldelete pre_auxConcurrent deletions may stall process and create
chains of aux nodes.The last deletion follows the back_links of the
deleted cells.After all deletions the list will have no extra
aux_nodes
Try_delete(cursor c) {Try_delete(cursor c) {
};};
38
Universal Algorithm (a.k.a. Universal Method) An algorithm that provides lock-free functionality for ANY generic
ADT is called universal. Universal meaning “for any.” This requires a powerful synchronization primitive. This is an application that defines a primitives strength.
Universal Primitive A universal primitive can be used to provide lock-free functionality for
any generic Data Type. A universal primitive can also solve the consensus problem.
Analogous Problems Generic Lock-Free ADT is analogous to the consensus problem. If a primitive is powerful enough to solve one it can also solve the
other.
UniversalUniversal
39
Can be implemented using Compare&Swap
Test&Set Sets new value to TRUE.
Fetch&AddAdds an arbitrary value to shared variable.
Test&Set Fetch&AddTest&Set Fetch&Add
40
Created algorithms and data structures that directly implement a non-blocking singly-linked list.
Allows multiple processes to traverse, insert and delete.
Using only commonly available Compare&Swap. Single word version Commonly available on most systems
ValoisValois
41
An implementation is wait-free if every process finishes in a bounded number of steps,
regardless of interleaving.
Wait-FreeWait-Free