non-blocking binary search...

62
Non-blocking Binary Search Trees Faith Ellen, University of Toronto Panagiota Fatourou, ICS FORTH & University of Crete Eric Ruppert, York University Franck van Breugel, York University July 26, 2010 Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Upload: others

Post on 05-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-blocking Binary Search Trees

Faith Ellen, University of Toronto

Panagiota Fatourou, ICS FORTH & University of Crete

Eric Ruppert, York University

Franck van Breugel, York University

July 26, 2010

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 2: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

State of the Art

The Java standard library has several non-blocking datastructures, but no search trees.

“You might wonder why this doesn’t use some kind of searchtree instead . . . . The reason is that there are no known efficientlock-free insertion and deletion algorithms for search trees.”

Doug Lea in java.util.concurrent.ConcurrentSkipListMap

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 3: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-Blocking Data Structures

Non-blocking: some operation makes progress.

Studied for 20+ yearsUniversal constructions [1988–present]

Disadvantage: inefficientArray-based structures [1990–2005]

snapshots, stacks, queuesList-based structures [1995–2005]

singly-linked lists, stacks, queues, skip listsA few others [1995–present]

union-find, ...

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 4: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-Blocking Data Structures

Non-blocking: some operation makes progress.

Studied for 20+ yearsUniversal constructions [1988–present]

Disadvantage: inefficientArray-based structures [1990–2005]

snapshots, stacks, queuesList-based structures [1995–2005]

singly-linked lists, stacks, queues, skip listsA few others [1995–present]

union-find, ...

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 5: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-Blocking Data Structures

Non-blocking: some operation makes progress.

Studied for 20+ yearsUniversal constructions [1988–present]

Disadvantage: inefficientArray-based structures [1990–2005]

snapshots, stacks, queuesList-based structures [1995–2005]

singly-linked lists, stacks, queues, skip listsA few others [1995–present]

union-find, ...

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 6: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-Blocking Data Structures

Non-blocking: some operation makes progress.

Studied for 20+ yearsUniversal constructions [1988–present]

Disadvantage: inefficientArray-based structures [1990–2005]

snapshots, stacks, queuesList-based structures [1995–2005]

singly-linked lists, stacks, queues, skip listsA few others [1995–present]

union-find, ...

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 7: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Non-Blocking Data Structures

Non-blocking: some operation makes progress.

Studied for 20+ yearsUniversal constructions [1988–present]

Disadvantage: inefficientArray-based structures [1990–2005]

snapshots, stacks, queuesList-based structures [1995–2005]

singly-linked lists, stacks, queues, skip listsA few others [1995–present]

union-find, ...

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 8: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Prior Work on Concurrent Search Trees

Many lock-based implementations [1978–present]Valois outlined how his linked lists might generalize toBSTs [1995]

complicated and lacks detail

Non-blocking BST [Fraser 2003]

uses 8-word CAS

Bender et al. outlined how their lock-based cache-obliviousB-trees might be made non-blocking [2005]

lacks details and proof of correctness

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 9: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

New Result

A non-blocking implementation of BSTs from single-word CAS.

Some properties:Conceptually simpleFast searchesConcurrent updates to different parts of tree do not conflictTechnique seems generalizableExperiments show good performance

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 10: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Model

AsynchronousCrash failures allowedShared memory with single-word compare-and-swapLinearizable

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 11: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Leaf-oriented BST

DefinitionOne leaf for each key in setInternal nodes used only for routingEach internal node has exactly 2 childrenBST property:

keys ≥ K

K

keys < K

Advantages of Leaf-Oriented TreesDeletions much simplerAverage depth only slightly higher

Example

Leaf-oriented BSTstoring key set{A,B,C,F}

F

A

B

C

B

C

E

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 12: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Leaf-oriented BST

DefinitionOne leaf for each key in setInternal nodes used only for routingEach internal node has exactly 2 childrenBST property:

keys ≥ K

K

keys < K

Advantages of Leaf-Oriented TreesDeletions much simplerAverage depth only slightly higher

Example

Leaf-oriented BSTstoring key set{A,B,C,F}

F

A

B

C

B

C

E

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 13: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion (non-concurrent version)

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create new leaf, replacement leaf,

and one internal node4 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 14: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion (non-concurrent version)

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create new leaf, replacement leaf,

and one internal node4 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 15: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion (non-concurrent version)

C

E

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create new leaf, replacement leaf,

and one internal node4 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 16: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion (non-concurrent version)

C

E

D

D

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create new leaf, replacement leaf,

and one internal node4 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 17: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion (non-concurrent version)

D

D

C

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create new leaf, replacement leaf,

and one internal node4 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 18: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion (non-concurrent version)

A

B

F

B E

C

CDelete(C)

1 Search for C2 Remember leaf, its parent and

grandparent3 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 19: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion (non-concurrent version)

A

B

F

B E

C

CDelete(C)

1 Search for C2 Remember leaf, its parent and

grandparent3 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 20: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion (non-concurrent version)

E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 21: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion (non-concurrent version)

A

B

F

B E

C

CDelete(C)

1 Search for C2 Remember leaf, its parent and

grandparent3 Swing pointer

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 22: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Challenges of Concurrency (1)

F

B

A

B

E

C

C

Concurrent Delete(B) and Delete(C).

⇒ C is still reachable from the root!

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 23: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Challenges of Concurrency (1)

F

B

A

B

E

C

C

Concurrent Delete(B) and Delete(C).

⇒ C is still reachable from the root!

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 24: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Challenges of Concurrency (2)

F

B

A

B

C

E

C

Concurrent Delete(C) and Insert(D).

⇒ D is not reachable from the root!

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 25: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Challenges of Concurrency (2)

D

C D

F

B

A

B

C

E

C

Concurrent Delete(C) and Insert(D).

⇒ D is not reachable from the root!

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 26: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Coordination Required

Crucial problem: A node’s child pointer is changed while thenode is being removed from the tree.

Solution: Updates to the same part of the tree must coordinate.

Desirable Properties of Coordination SchemeAvoid exclusive-access locksMaintain invariant that tree is always a BSTAllow searches to pass unhinderedMake updates as local as possibleAlgorithmic simplicity

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 27: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Coordination Required

Crucial problem: A node’s child pointer is changed while thenode is being removed from the tree.

Solution: Updates to the same part of the tree must coordinate.

Desirable Properties of Coordination SchemeAvoid exclusive-access locksMaintain invariant that tree is always a BSTAllow searches to pass unhinderedMake updates as local as possibleAlgorithmic simplicity

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 28: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Flags and Marks

An internal node can be either flagged or marked (but not both).Status is changed using CAS.

FlagIndicates that an update is changing a child pointer.

Before changing an internal node x ’s child pointer, flag x .Unflag x after its child pointer has been changed.

MarkIndicates an internal node has been (or soon will be) removedfrom the tree.

Before removing an internal node, mark it.Node remains marked forever.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 29: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Flags and Marks

An internal node can be either flagged or marked (but not both).Status is changed using CAS.

FlagIndicates that an update is changing a child pointer.

Before changing an internal node x ’s child pointer, flag x .Unflag x after its child pointer has been changed.

MarkIndicates an internal node has been (or soon will be) removedfrom the tree.

Before removing an internal node, mark it.Node remains marked forever.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 30: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Flags and Marks

An internal node can be either flagged or marked (but not both).Status is changed using CAS.

FlagIndicates that an update is changing a child pointer.

Before changing an internal node x ’s child pointer, flag x .Unflag x after its child pointer has been changed.

MarkIndicates an internal node has been (or soon will be) removedfrom the tree.

Before removing an internal node, mark it.Node remains marked forever.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 31: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 32: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 33: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

C

E

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 34: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

C

E

D

D

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 35: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

C

E

D

D

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 36: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

C

E

D

D

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 37: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Insertion Algorithm

D

D

C

E

C

A

B

F

C

B

Insert(D)1 Search for D2 Remember leaf and its parent3 Create three new nodes4 Flag parent (if this fails, retry from

scratch)5 Swing pointer (using CAS)6 Unflag parent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 38: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

A

B

F

B E

C

C

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 39: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

A

B

F

B E

C

C

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 40: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 41: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 42: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

6E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 43: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

6E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 44: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Deletion Algorithm

6E

C

C

A

B

F

B

Delete(C)1 Search for C2 Remember leaf, its parent and

grandparent3 Flag grandparent (if this fails, retry

from scratch)4 Mark parent (if this fails, unflag

grandparent and retry from scratch)5 Swing pointer (using CAS)6 Unflag grandparent

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 45: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case I: Delete(C)’s flag succeeds.

⇒ Even if Delete(B)’s flag succeeds, itsmark will fail.

⇒ Delete(C) will completeDelete(B) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 46: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

C

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case I: Delete(C)’s flag succeeds.

⇒ Even if Delete(B)’s flag succeeds, itsmark will fail.

⇒ Delete(C) will completeDelete(B) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 47: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

B

C

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case I: Delete(C)’s flag succeeds.

⇒ Even if Delete(B)’s flag succeeds, itsmark will fail.

⇒ Delete(C) will completeDelete(B) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 48: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

6

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case I: Delete(C)’s flag succeeds.

⇒ Even if Delete(B)’s flag succeeds, itsmark will fail.

⇒ Delete(C) will completeDelete(B) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 49: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

6

B

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case II: Delete(B)’s flag and marksucceed.

⇒ Delete(C)’s flag fails.

⇒ Delete (B) will completeDelete(C) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 50: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

6

B

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case II: Delete(B)’s flag and marksucceed.

⇒ Delete(C)’s flag fails.

⇒ Delete (B) will completeDelete(C) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 51: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Conflicting Deletions Now Work

6

F

B

A

B

E

C

C Concurrent Delete(B) and Delete(C)

Case II: Delete(B)’s flag and marksucceed.

⇒ Delete(C)’s flag fails.

⇒ Delete (B) will completeDelete(C) will retry

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 52: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Locks

Can think of flag or mark as a lock on the child pointers of anode.

Flag corresponds to temporary ownership of lock.Mark corresponds to permanent ownership of lock.

RemarkEasier version of these ideas were used for singly-linked lists.Locking two child pointers with one flag or mark is harder.

RemarkEach update needs only one or two locks, searches need none.(Previous lock-based BSTs use more locks.)

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 53: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Locks

Can think of flag or mark as a lock on the child pointers of anode.

Flag corresponds to temporary ownership of lock.Mark corresponds to permanent ownership of lock.

RemarkEasier version of these ideas were used for singly-linked lists.Locking two child pointers with one flag or mark is harder.

RemarkEach update needs only one or two locks, searches need none.(Previous lock-based BSTs use more locks.)

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 54: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Locks

Can think of flag or mark as a lock on the child pointers of anode.

Flag corresponds to temporary ownership of lock.Mark corresponds to permanent ownership of lock.

RemarkEasier version of these ideas were used for singly-linked lists.Locking two child pointers with one flag or mark is harder.

RemarkEach update needs only one or two locks, searches need none.(Previous lock-based BSTs use more locks.)

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 55: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Wait a second . . .

We want the data structure to be non-blocking!

Whenever “locking” a node, leave a key under the doormat.

A flag or mark is actually a pointer to a small record that tells aprocess how to help the original operation.

If an operation fails to acquire a lock, it helps complete theupdate that holds the lock before retrying.

Thus, locks are owned by operations, not processes.

Some similarities to Barnes’s cooperative technique.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 56: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Wait a second . . .

We want the data structure to be non-blocking!

Whenever “locking” a node, leave a key under the doormat.

A flag or mark is actually a pointer to a small record that tells aprocess how to help the original operation.

If an operation fails to acquire a lock, it helps complete theupdate that holds the lock before retrying.

Thus, locks are owned by operations, not processes.

Some similarities to Barnes’s cooperative technique.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 57: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Wait a second . . .

We want the data structure to be non-blocking!

Whenever “locking” a node, leave a key under the doormat.

A flag or mark is actually a pointer to a small record that tells aprocess how to help the original operation.

If an operation fails to acquire a lock, it helps complete theupdate that holds the lock before retrying.

Thus, locks are owned by operations, not processes.

Some similarities to Barnes’s cooperative technique.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 58: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Searching

Searches just traverse edges of the BST until reaching a leaf.

They can ignore flags and marks.

Can prove by induction that each node visited by a Search(K )was on the search path for K at some time during the Search.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 59: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Progress

Goal: Show data structure is non-blocking (some operationcompletes).

If an Insert successfully flags, it finishes.If a Delete successfully flags and marks, it finishes.If updates stop happening, searches must finish.

One CAS fails only if another succeeds.⇒ A successful CAS guarantees progress, except for aDelete’s flag.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 60: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Progress: The Hard Case

B

C

E

A

B

F

B

E F

E

C

C

A Delete may flag, then fail to mark, thenunflag to retry.

⇒ The Delete’s changes may causeother CAS’s to fail.

However, lowest Delete will makeprogress.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 61: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Some Details Omitted

The formal proof of correctness is surprisingly difficult(20 pages long).

See the Technical Report.

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees

Page 62: Non-blocking Binary Search Treespdfs.semanticscholar.org/00b3/ebd315991e5b5f4e6beec2e1488281368028.pdfEllen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees. Insertion

Further Work

Balancing the treeProving worst-case complexity boundsCan same approach yield (efficient) wait-free BSTs?(Or at least wait-free Finds?)Other data structures

Ellen, Fatourou, Ruppert, van Breugel Non-blocking Binary Search Trees