Presentation is loading. Please wait.

Presentation is loading. Please wait.

Model Checking Lock-Free Binary Search Tree Presented by Joanna Helga.

Similar presentations


Presentation on theme: "Model Checking Lock-Free Binary Search Tree Presented by Joanna Helga."— Presentation transcript:

1 Model Checking Lock-Free Binary Search Tree Presented by Joanna Helga

2 Leaf Oriented BST 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 Structure A Helper Node A Node Leaf Internal left : Node right : Node key : int 2 Internal left : Node right : Node update : AtomicStampedReference HelperNodeint 0=Clean1=IFlag2=DFlag3=Mark

4 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 leaf parent Is parent node clear?

5 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 leaf parent Is parent node clear? grandparent Is grandparent node clear?

6 SearchReturn Class SearchReturn l : Node p : Node gp : Node pupdate : AtomicStampedReference gpupdate : AtomicStampedReference

7 Helper Node Structure Flag p : Node l : Node IFlag newinternal: Node DFlag gp : Node pupdate : AtomicStampedReference

8 Checking insert(10) insert(20) delete(10) || delete(20) insert(10) insert(20) delete(10) || delete(20) insert(10) delete(10) || insert(20) insert(10) delete(10) || insert(20) insert(10) || insert(20) Dictionary d; Leaf l; int mykey; … d.Insert(mykey); l = d.Find(mykey); assert(l != null); assert(l.key == mykey); d.Delete(mykey); l = d.Find(mykey); assert(l == null);

9 Test #1 d.Insert(mykey ); l = d.Find(mykey); assert(l != null); assert(l.key == mykey); assert error null pointer exception Insert operation returns “TRUE”, but the key was not inserted Insert operation returns “TRUE”, but the key was not inserted

10 Insert - Detailed SearchRet gpupdate pupdate gp p l gp p l update referencestamp referencestamp flag search location if (pupdate.stamp = clean) then // try insert here… else // help gp here… if (pupdate.stamp = clean) then create new node create helper node op p.update.CAS(pupdate, ) if (CAS successful) then // actually modify the BST why we need CAS here? CAS always successful !

11 Insert - Fixed gp p l update referencestamp referencestamp flag SearchRet gpflag gpstamp pflag pstamp gp p l int if (p.update.stamp = clean) then create new node create helper node op p.update.CAS(, ) if (CAS successful) then // actually modify the BST

12 Test #2 insert(10) insert(20) delete(10) || delete(20) insert(10) insert(20) delete(10) || delete(20) null pointer exception

13 Delete - Detailed gp p l update referencestamp referencestamp flag SearchRet gpflag gpstamp pflag pstamp gp p l search if (gp.update.stamp != 0) help(gp.update) else if(p.update.stamp != 0) help(p.update) else //try delete… // try delete create helper node op gp.update.CAS(, ) if(CAS successful) // try modify BST else help(gp.update) why we need CAS here? null pointer exception

14 Help & HelpMarked help(AtomicStampedReference update){ if(update.stamp = 1)//1=iflag helpinsert(update.reference); else if(update.stamp = 3)//3=mark helpmarked(update.reference); else if(update.stamp = 2)//2=dflag; helpdelete(update.reference); } private void helpmarked(DFlag op){ // Modify BST } op is null A node is marked, but doesn’t have pointer to HelperNode A node is marked, but doesn’t have pointer to HelperNode

15 HelpDelete boolean helpdelete(DFlag op){ boolean result; result = op.p.update.CAS(, ); if(result = true){ helpmarked(op); return true; } else // help p … CAS(, );

16 Test #3 No error detected insert(10) delete(10) || insert(20) insert(10) delete(10) || insert(20)


Download ppt "Model Checking Lock-Free Binary Search Tree Presented by Joanna Helga."

Similar presentations


Ads by Google