1 / 43

Lock-Free Linked Lists Using Compare-and-Swap

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?.

luella
Download Presentation

Lock-Free Linked Lists Using Compare-and-Swap

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Talk Title: Lock-Free Linked Lists Using Compare-and-Swap by John Valois Speaker’s Name: Larry Bush

  2. ConcurrentObject Shared Memory Pn P1 P2

  3. Lock-Free • No Mutual Exclusion • Appear Atomic • Lamport • Massalin and Pu

  4. Lock-Free Linked Lists?

  5. 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 • }

  6. Why is this important ? • Avoids Mutual Exclusion Problems • Convoying • Deadlock • Priority Inversion • Blocking • Busy Waiting

  7. Limitations of current implementations • Universal methods are not efficient (Herlihy). • Massalin and Pu’s method required the uncommon double word Compare&Swap.

  8. Benefits of new implementation • As quick as spin locks • Without blocking or busy waiting (wait free)

  9. Part 2Concurrent Linked List Cursor Cursor

  10. Traversal ( no problem ) Cursor Cursor

  11. Insert ( small problem ) s p q

  12. Insert ( small problem ) s p q

  13. Insert ( small problem ) s p swing pointer q

  14. Delete a b d

  15. Delete a b d

  16. Delete ( big problem ) a d b c Cursor Cursor

  17. Delete ( big problem ) a d b c Cursor Cursor

  18. Delete ( big problem ) Cursor a d b c Cursor

  19. Delete ( big problem ) Cursor a d b c Cursor

  20. Iterator ( at node b ) pre_aux a d b c pre_cell target

  21. Auxiliary nodes a d b c

  22. Step One a d b c

  23. Step Two a d b c

  24. Step Three a d b c

  25. Step Four a d b c

  26. Conclusion • Allows concurrent operations • Good for: • parallel processing • distributed memory • Should be used everywhere

  27. Questions/Facts

  28. 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)

  29. 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.

  30. Wait-Free • An implementation is wait-free if every process finishes in a bounded number of steps, • regardless of interleaving.

  31. 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.

  32. 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 )}

  33. ABA problem s p swing pointer q

  34. ABA Solutions • Double Compare&Swap • No Cell Reuse • Memory Management

  35. Insert ( p, x ) • q = new cell • Repeat • r = SafeRead ( p -> next ) • Write ( q -> next, r ) • until Compare&Swap( p -> next, r, q )

  36. struct Cursor {}; • node * target; // -> data • node * pre_aux; // -> preceding auxiliary node • node * pre_cell; // -> previous cell

  37. Update(cursor c) {}; • // Updates pointers in the cursor so that it becomes valid. • // removes double aux_node.

  38. 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

  39. 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.

  40. 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

  41. Contributions • Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree.

  42. Related Work • Lamport • Herlihy • Massalin and Pu

  43. 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

More Related