LOCKFREE BINARY SEARCH TREE Presented by Joanna Helga

LOCK-FREE BINARY SEARCH TREE Presented by Joanna Helga From draft paper “Lock-Free Binary Search Trees” by Eric Ruppert, Panagiota Fatourou, and Faith Ellen

BINARY SEARCH TREE (BST) Implements dictionary abstract data structure B A Each node can have 0 -2 children D C All nodes in left subtree of X has keys that smaller than key of X G E H All nodes in right subtree of X has keys that greater than (or equal to) key of X

LEAF ORIENTED BST Property #1 B Real keys are stored in leaf A Internal nodes stores dummy keys and exactly has 2 children D C Leaves stores only a key G E H

LEAF ORIENTED BST Property #2 Duplicate keys are not allowed H A Keys stored in internal nodes are not real keys, so they may have duplicates H C X H E H <X ≥X

INSERT OPERATION We also need to know Insert(E) this pointer, which is D’s parent B search for location create a node for E E D α E create dummy node with key=max(E, D) point its left and right child to D and E change B’s pointer to the new dummy node

DELETE OPERATION We also need to know this pointer, which is C’s Delete(C) grandparent B Search C’s location Change B’s child pointer to C’s sibling And this pointer, which D α can be found if we know C’s parent C β

UPDATE OPERATIONS Update operations only change 1 pointer in the shared data structure However, simply using Compare-and-swap for updating this pointer can have some problem B Insert Delete B E D α E α β

PROBLEM Example #1 B A op 1: Delete(C) D C E is not deleted ! op 2: Delete(E) G E Problem arises when op 1 splice node D out of tree, while op 2 tries to update its child pointer H

PROBLEM Example #2 B A op 2: Delete(E) D C op 1: Insert(F) Problem arises when op 2 splice node G out of tree, while op 1 tries to update its child pointer G F F is not inserted ! E F H

MARK & FLAG BITS To overcome the previous problem, we add MARK and FLAG bits to each node MARK bit indicate that a node will be spliced out soon FLAG bit indicate that a node will have one of its child pointer changed soon We want to avoid a node being spliced out and changed its child pointer at same time. This can be achieved by using these 2 bits, that stored in a single word.

KEY STEPS OF INSERT CAS’s for Insert: B E D α E Flag B Change it’s child pointer un. Flag B

KEY STEPS OF DELETE CAS’s for Delete B D α C β Flag B Mark D Change B’s child pointer un. Flag B

LOCK-FREE PROPERTY MARK and FLAG bits behaves like a lock When an operation tries to update something, it has to own the lock first, and unlock it after the update is done If a process who holds the lock dies, it will prevent other processes to access that part of the tree forever ! Use HELPING procedure to prevent locking

HELPER NODE Before a process tries to hold a lock, it stores enough information on a Helper Node • Leaf pointer • Parent pointer • Grandparent pointer • Last known MARK and FLAG bits statuses of parent node • Pointer to the node to be inserted (for Insert only) A pointer to this helper node is stored in same field as MARK and FLAG bit
- Slides: 14