430 likes | 621 Views
Talk Title:. Lock-Free Linked Lists Using Compare-and-Swap. by John Valois. Speaker’s Name:. Larry Bush. Concurrent Object. Shared Memory. P n. P 1. P 2. Lock-Free. No Mutual Exclusion Appear Atomic Lamport Massalin and Pu. Lock-Free Linked Lists?.
E N D
Talk Title: Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Larry Bush
ConcurrentObject Shared Memory Pn P1 P2
Lock-Free • No Mutual Exclusion • Appear Atomic • Lamport • Massalin and Pu
Compare&Swap Synchronization Primitive • bool Compare&Swap ( Type * x, Type old, Type new) { • // BEGIN ATOMIC • if *x != old { • *x = new; • return TRUE; • } else { • return FALSE • } • // END ATOMIC • }
Why is this important ? • Avoids Mutual Exclusion Problems • Convoying • Deadlock • Priority Inversion • Blocking • Busy Waiting
Limitations of current implementations • Universal methods are not efficient (Herlihy). • Massalin and Pu’s method required the uncommon double word Compare&Swap.
Benefits of new implementation • As quick as spin locks • Without blocking or busy waiting (wait free)
Part 2Concurrent Linked List Cursor Cursor
Traversal ( no problem ) Cursor Cursor
Insert ( small problem ) s p q
Insert ( small problem ) s p q
Insert ( small problem ) s p swing pointer q
Delete a b d
Delete a b d
Delete ( big problem ) a d b c Cursor Cursor
Delete ( big problem ) a d b c Cursor Cursor
Delete ( big problem ) Cursor a d b c Cursor
Delete ( big problem ) Cursor a d b c Cursor
Iterator ( at node b ) pre_aux a d b c pre_cell target
Auxiliary nodes a d b c
Step One a d b c
Step Two a d b c
Step Three a d b c
Step Four a d b c
Conclusion • Allows concurrent operations • Good for: • parallel processing • distributed memory • Should be used everywhere
Why do you say this is lock-free if it uses a mutual exclusion 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)
Universal • 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.
Wait-Free • An implementation is wait-free if every process finishes in a bounded number of steps, • regardless of interleaving.
Aux 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.
Swinging the Pointer • ptr = find ptr of interest • repeat • old = Read( ptr ); • new = compute new pointer value • r = Compare&Swap(ptr, old, new) • until ( r = TRUE )}
ABA problem s p swing pointer q
ABA Solutions • Double Compare&Swap • No Cell Reuse • Memory Management
Insert ( p, x ) • q = new cell • Repeat • r = SafeRead ( p -> next ) • Write ( q -> next, r ) • until Compare&Swap( p -> next, r, q )
struct Cursor {}; • node * target; // -> data • node * pre_aux; // -> preceding auxiliary node • node * pre_cell; // -> previous cell
Update(cursor c) {}; • // Updates pointers in the cursor so that it becomes valid. • // removes double aux_node.
Try_delete(cursor c) {}; • c.pre_cell = next // deletes cell • back_link = c->pre_cell • delete pre_aux • Concurrent 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
Test&Set Fetch&Add • Can be implemented using Compare&Swap • Test&Set • Sets new value to TRUE. • Fetch&Add • Adds an arbitrary value to shared variable.
Valois • 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
Contributions • Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree.
Related Work • Lamport • Herlihy • Massalin and Pu
Lamport • Discovered that mutual exclusion problems can be avoided using lock-free methods. • Gave the first lock-free algorithm for the single writer/ multiple reader shared variable. • Led to more research on the topic. • 27 years