Talk Title LockFree Linked Lists Using CompareandSwap by
Talk Title: Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Larry Bush 1
Concurrent Object Shared Memory P 1 P 2 Pn 2
Lock-Free l No Mutual Exclusion l Appear Atomic l Lamport l Massalin and Pu 3
Lock-Free Linked Lists? 4
Compare&Swap Synchronization Primitive l bool Compare&Swap ( Type * x, Type old, Type new) { l l // BEGIN ATOMIC if *x != old { • *x = new; • return TRUE; l } else { • return FALSE l l l } // END ATOMIC } 5
Why is this important ? l Avoids l Mutual Exclusion Problems Convoying Blocking l Deadlock l Priority Inversion Busy Waiting 6
Limitations of current implementations l Universal methods are not efficient (Herlihy). l Massalin and Pu’s method required the uncommon double word Compare&Swap. 7
Benefits of new implementations l As quick as spin locks l Without blocking or busy waiting (wait free) 8
Part 2 Concurrent Linked List Cursor 9
Traversal ( no problem ) Cursor 10
Insert ( small problem ) s p q 11
Insert ( small problem ) s p q 12
Insert ( small problem ) s p swing pointer q 13
Delete a b d 14
Delete a b d 15
Delete ( big problem ) a d b Cursor c Cursor 16
Delete ( big problem ) a d b Cursor c Cursor 17
Delete ( big problem ) Cursor a d b c Cursor 18
Delete ( big problem ) Cursor a d b c Cursor 19
Auxiliary nodes a b c d 20
Delete ( with auxiliary nodes ) a d b c 21
Delete ( with auxiliary nodes ) a d b c 22
Delete ( with auxiliary nodes ) a d b c 23
Delete ( with auxiliary nodes ) a d b c 24
Conclusion l Allows l Good concurrent operations for: lparallel processing ldistributed memory l Should be used everywhere 25
Questions/Facts 26
ABA problem s p swing pointer q 27
ABA Solutions l Double l No Compare&Swap Cell Reuse l Memory Management 28
Aux Nodes l Insertion of new cells takes place between an auxiliary node and an existing regular cell. l Chains of auxilary nodes are allowed. An auxilary node is not required to have a real cell node before and after it. 29
Related Work l Lamport l Herlihy l Massalin and Pu 30
Contributions l Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree. 31
Why do you say this is lock-free if it uses a mutual exclusion primitive? l Limited to atomic actions provided by the hardware. l Only when swinging pointers. l Allows simultaneous traversal, insertion and deletion. l Lamport (made the distinction) l Massalin and Pu (coined the term) 32
Swinging the Pointer l ptr = find ptr of interest l repeat l l old = Read( ptr ); new = compute new pointer value r = Compare&Swap(ptr, old, new) until ( r = TRUE )} 33
Insert ( p, x ) l q = new cell l Repeat l l l r = Safe. Read ( p -> next ) Write ( q -> next, r ) until Compare&Swap( p -> next, r, q ) 34
struct Cursor { l node * target; // -> data l node * pre_aux; // -> preceding auxiliary node l node * pre_cell; // -> previous cell }; 35
Update(cursor c) { l // Updates pointers in the cursor so that it becomes valid. l // removes double aux_node. }; 36
Try_delete(cursor c) { c. pre_cell = next // deletes cell l back_link = c->pre_cell l delete pre_aux l Concurrent deletions may stall process and create chains of aux nodes. l The last deletion follows the back_links of the deleted cells. l After all deletions the list will have no extra aux_nodes l }; 37
Universal l Universal Algorithm (a. k. a. Universal Method) l l Universal Primitive l l l 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. 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 l l 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. 38
Test&Set Fetch&Add l Can be implemented using Compare&Swap l Test&Set l Sets new value to TRUE. l Fetch&Add l Adds an arbitrary value to shared variable. 39
Valois l Created algorithms and data structures that directly implement a non-blocking singly-linked list. l Allows multiple processes to traverse, insert and delete. l Using only commonly available Compare&Swap. Single word version l Commonly available on most systems l 40
Wait-Free l An implementation is wait-free if every process finishes in a bounded number of steps, l regardless of interleaving. 41
Lamport l Discovered that mutual exclusion problems can be avoided using lock-free methods. l Gave the first lock-free algorithm for the single writer/ multiple reader shared variable. l Led l 27 to more research on the topic. years 42
- Slides: 42