Lock free linked lists using compare and swap
This presentation is the property of its rightful owner.
Sponsored Links
1 / 43

Lock-Free Linked Lists Using Compare-and-Swap PowerPoint PPT Presentation


  • 93 Views
  • Uploaded on
  • Presentation posted in: General

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

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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

ConcurrentObject

Shared Memory

Pn

P1

P2


Lock free

Lock-Free

  • No Mutual Exclusion

  • Appear Atomic

  • Lamport

  • Massalin and Pu


Lock free linked lists

Lock-Free Linked Lists?


Compare swap synchronization primitive

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

    Why is this important ?

    • Avoids Mutual Exclusion Problems

      • Convoying

      • Deadlock

      • Priority Inversion

    • Blocking

    • Busy Waiting


    Limitations of current implementations

    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

    Benefits of new implementation

    • As quick as spin locks

    • Without blocking or busy waiting (wait free)


    Part 2 concurrent linked list

    Part 2Concurrent Linked List

    Cursor

    Cursor


    Traversal no problem

    Traversal ( no problem )

    Cursor

    Cursor


    Insert small problem

    Insert ( small problem )

    s

    p

    q


    Insert small problem1

    Insert ( small problem )

    s

    p

    q


    Insert small problem2

    Insert ( small problem )

    s

    p

    swing pointer

    q


    Delete

    Delete

    a

    b

    d


    Delete1

    Delete

    a

    b

    d


    Delete big problem

    Delete ( big problem )

    a

    d

    b

    c

    Cursor

    Cursor


    Delete big problem1

    Delete ( big problem )

    a

    d

    b

    c

    Cursor

    Cursor


    Delete big problem2

    Delete ( big problem )

    Cursor

    a

    d

    b

    c

    Cursor


    Delete big problem3

    Delete ( big problem )

    Cursor

    a

    d

    b

    c

    Cursor


    Iterator at node b

    Iterator ( at node b )

    pre_aux

    a

    d

    b

    c

    pre_cell

    target


    Auxiliary nodes

    Auxiliary nodes

    a

    d

    b

    c


    Step one

    Step One

    a

    d

    b

    c


    Step two

    Step Two

    a

    d

    b

    c


    Step three

    Step Three

    a

    d

    b

    c


    Step four

    Step Four

    a

    d

    b

    c


    Conclusion

    Conclusion

    • Allows concurrent operations

    • Good for:

      • parallel processing

      • distributed memory

  • Should be used everywhere


  • Questions facts

    Questions/Facts


    Why do you say this is lock free if it uses a mutual exclusion primitive

    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

    • 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

    Wait-Free

    • An implementation is wait-free if every process finishes in a bounded number of steps,

    • regardless of interleaving.


    Aux nodes

    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

    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

    ABA problem

    s

    p

    swing pointer

    q


    Aba solutions

    ABA Solutions

    • Double Compare&Swap

    • No Cell Reuse

    • Memory Management


    Insert p x

    Insert ( p, x )

    • q = new cell

    • Repeat

      • r = SafeRead ( p -> next )

      • Write ( q -> next, r )

  • until Compare&Swap( p -> next, r, q )


  • Struct cursor

    struct Cursor {};

    • node * target;// -> data

    • node * pre_aux; // -> preceding auxiliary node

    • node * pre_cell; // -> previous cell


    Update cursor c

    Update(cursor c) {};

    • // Updates pointers in the cursor so that it becomes valid.

    • // removes double aux_node.


    Try delete cursor c

    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

    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

    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

    Contributions

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


    Related work

    Related Work

    • Lamport

    • Herlihy

    • Massalin and Pu


    Lamport

    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


  • Login