LockFree Linked Lists Using CompareandSwap - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

LockFree Linked Lists Using CompareandSwap

Description:

... Using Compare-and-Swap. by John Valois. Speaker's Name: Talk Title: ... Lock-Free Structures & Memory Management Techniques for linked list, dictionary and tree. ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 44
Provided by: csr22
Category:

less

Transcript and Presenter's Notes

Title: LockFree Linked Lists Using CompareandSwap


1
Lock-Free Linked Lists Using Compare-and-Swap
Talk Title
  • by John Valois

Speakers Name
Larry Bush
2
ConcurrentObject
Shared Memory
P1
Pn
P2
3
Lock-Free
  • No Mutual Exclusion
  • Appear Atomic
  • Lamport
  • Massalin and Pu

4
Lock-Free Linked Lists?
5
CompareSwap Synchronization Primitive
  • bool CompareSwap ( 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 Pus method required the uncommon
    double word CompareSwap.

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
q
swing pointer
14
Delete
b
a
d
15
Delete
b
a
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
c
b
pre_cell
target
21
Auxiliary nodes
a
d
c
b
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 CompareSwap(ptr, old, new)
  • until ( r TRUE )

33
ABA problem
s
p
q
swing pointer
34
ABA Solutions
  • Double CompareSwap
  • No Cell Reuse
  • Memory Management

35
Insert ( p, x )
  • q new cell
  • Repeat
  • r SafeRead ( p -gt next )
  • Write ( q -gt next, r )
  • until CompareSwap( p -gt next, r, q )

36
struct Cursor
  • node target // -gt data
  • node pre_aux // -gt preceding auxiliary node
  • node pre_cell // -gt 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-gtpre_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
TestSet FetchAdd
  • Can be implemented using CompareSwap
  • TestSet
  • Sets new value to TRUE.
  • FetchAdd
  • 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 CompareSwap.
  • 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
Write a Comment
User Comments (0)
About PowerShow.com