Download presentation
Presentation is loading. Please wait.
Published byJennifer Baldwin Modified over 9 years ago
1
Lock-Free Binary Search Tree Presented by Joanna Helga
2
Leaf Oriented Binary Search Tree Implements Dictionary ADT Operations: Find, Insert, Delete Real keys are stored in leaf Internal nodes stores dummy keys and exactly has 2 children Leaves stores only a key B A D C G EH
3
Node Implementation Node LeafInternal left : Node right : Node key : int 2
4
Dictionary Implementation Dictionary root : Internal Dictionary() Find() : Leaf Insert(int) : boolean Delete(int) : boolean ∞2∞2 ∞1∞1 ∞2∞2 root is always Internal Node
5
Insert Insert(E) search for location create Leaf(E) create Internal(max(E,D)) point its left and right child to D and E Flag B change B’s pointer to the new Internal node Unflag B B D α E E B
6
Flagging a node Atomically set the node’s status to Flag and set it’s helper pointer to a Helper Node 4 Kinds of Node’s status: Clean IFlag DFlag Mark A Helper Node A
7
Implementation Using AtomicStampedReference HelperNodeint 0=Clean1=IFlag2=DFlag3=Mark
8
HelperNode Implementation Flag p : Node l : Node IFlag newinternal: Node DFlag gp : Node pupdate : AtomicStampedReference Internal left : Node right : Node update : AtomicStampedReference
9
Delete Delete(C) Search C’s location Flag B (grandparent) Mark D (parent) Change B’s child pointer to C’s sibling Unflag B B D α C β B D
10
CAS-Child Many processes can try to help one operation Use CAS to change child pointer to ensure only one process successful B D α E E B α β InsertDelete
11
Blocking BST Implemented using synchronization Node LeafInternal left : Node right : Node key : int 2 Dictionary root : Internal Dictionary() Find() : Leaf Insert(int) : boolean Delete(int) : boolean Not using Helper Node
12
Search public SearchRet Search(int key){ synchronized(this){ this.activereaders++; } // traverse the tree synchronized(this){ this.activereaders--; if(this.activereaders == 0) this.notify(); } // return }
13
Insert public boolean Insert(int key){ // create new leaf and new sibling // create parent for them synchronized(this){ while(this.activereaders != 0){…} // modify BST this.notify(); }
14
Delete public boolean Delete(int key){ // find l's sibling synchronized(this){ while(this.activereaders != 0){…} // modify BST this.notify(); }
15
Performance Comparison: Add Only Blocking Algorithm
16
Performance Comparison: Add Only Non-Blocking Algorithm
17
Performance Comparison: Add Only Blocking V.S. Non-Blocking
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.