160 likes | 198 Vues
Model Checking Lock-Free Binary Search Tree. Presented by Joanna Helga. 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. E. H.
E N D
Model CheckingLock-Free Binary Search Tree Presented by Joanna Helga
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 E H
Node Structure Node 2 key : int Leaf Internal left : Node right : Node Internal HelperNode int left : Node right : Node update : AtomicStampedReference<Flag> Helper Node A A 0=Clean 1=IFlag 2=DFlag 3=Mark
Insert Is parent node clear? parent 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 B E leaf D E α
Delete Is grandparent node clear? parent grandparent Delete(C) Search C’s location Flag B (grandparent) Mark D (parent) Change B’s child pointer to C’s sibling Unflag B B B Is parent node clear? D D α leaf C β
SearchReturn Class SearchReturn l : Node p : Node gp : Node pupdate: AtomicStampedReference<Flag> gpupdate : AtomicStampedReference<Flag>
Helper Node Structure Flag p : Node l : Node IFlag DFlag newinternal: Node gp : Node pupdate : AtomicStampedReference<Flag>
Checking 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); insert(10) || insert(20) insert(10) insert(20) delete(10) || delete(20) insert(10) delete(10) || insert(20)
Test #1 assert error d.Insert(mykey); l = d.Find(mykey); assert(l != null); assert(l.key == mykey); null pointer exception Insert operation returns “TRUE”, but the key was not inserted
Insert - Detailed flag gp SearchRet gpupdate pupdate gp p l update flag p update if (pupdate.stamp = clean) then create new node create helper node op p.update.CAS(pupdate, <op,1>) if (CAS successful) then // actually modify the BST reference reference search location if (pupdate.stamp = clean) then // try insert here… else // help gp here… stamp stamp l why we need CAS here? CAS always successful !
Insert - Fixed flag gp SearchRet int gpflag gpstamp pflag pstamp gp p l update int flag p update reference reference stamp stamp if (p.update.stamp = clean) then create new node create helper node op p.update.CAS(<pflag,0>, <op,1>) if (CAS successful) then // actually modify the BST l
Test #2 insert(10) insert(20) delete(10) || delete(20) null pointer exception
Delete - Detailed flag gp SearchRet gpflag gpstamp pflag pstamp gp p l update flag p update // try delete create helper node op gp.update.CAS(<gpflag,0>, <op,2>) if(CAS successful) // try modify BST else help(gp.update) search if (gp.update.stamp != 0) help(gp.update) else if(p.update.stamp != 0) help(p.update) else //try delete… reference reference stamp stamp l why we need CAS here? null pointer exception
Help & HelpMarked help(AtomicStampedReference<Flag> 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 } A node is marked, but doesn’t have pointer to HelperNode op is null
HelpDelete boolean helpdelete(DFlag op){ boolean result; result = op.p.update.CAS(<op.pflag, op.pstamp>, <op.pflag, 3>); if(result = true){ helpmarked(op); return true; } else // help p … CAS(<op.pflag, op.pstamp>, <op, 3>);
Test #3 No error detected insert(10) delete(10) || insert(20)