/
A Provably Correct Scalable Concurrent Skip List Maurice Herlihy  Yossi Lev  Victor Luchangco A Provably Correct Scalable Concurrent Skip List Maurice Herlihy  Yossi Lev  Victor Luchangco

A Provably Correct Scalable Concurrent Skip List Maurice Herlihy Yossi Lev Victor Luchangco - PDF document

pasty-toler
pasty-toler . @pasty-toler
Follow
538 views
Uploaded On 2014-12-13

A Provably Correct Scalable Concurrent Skip List Maurice Herlihy Yossi Lev Victor Luchangco - PPT Presentation

We propose a new concurrent skip list algorithm distinguish ed by a combination of simplicity and scalability The algorit hm employs optimistic synchronization searching without acquiring locks followed by short lockbased validation before adding or ID: 23105

propose new

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "A Provably Correct Scalable Concurrent S..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

---------------157813152225+1Fig.1.Askiplistwithmaximumheightof4.Thenumberbeloweachnode(i.e.,arrayofnextpointers)isthekeyofthatnode,with1and+1asthekeysfortheleftandrightsentinelnodesrespectively.2BackgroundAskiplist[7]isalinkedlistthatissortedbykey,andinwhichnodesareassignedarandomheight,uptosomemaximumheight,wherethefrequencyofnodesofaparticularheightdecreasesexponentiallywiththeheight.Anodeinaskiplisthasnotjustonesuccessor,butanumberofsuccessorsequaltoitsheight:eachnodestoresapointertothenextnodeinthelistofeachheightuptoitsown.Forexample,anodeofheight3storesthree\nextpointers",onetothenextnodeofheight1,onetothenextnodeofheight2,andonetothenextnodeofheight3.Figure1illustratesaskiplistinwhichthekeysareintegers.Wethinkofaskiplistashavingseverallayersoflists,andwetalkaboutthepredecessorandsuccessorofanodeateachlayer.Thelistateachlayer,otherthanthebottomlayer,isasublistofthelistatthelayerbeneathit.Becausethereareexponentiallyfewernodesofgreaterheights,wecan ndakeyquicklybysearching rstathigherlayers,skippingoverlargenumbersofshorternodesandprogressivelyworkingdownwarduntilanodewiththedesiredkeyisfound,orelsethebottomlayerisreached.Thus,theexpectedtimecomplexityofskip-listoperationsislogarithmicinthelengthofthelist.Itisconvenienttohaveleftsentinelandrightsentinelnodes,atthebeginningandendofthelistsrespectively.Thesenodeshavethemaximumheight,andinitially,whentheskiplistisempty,therightsentinelisthesuccessoroftheleftsentinelateverylayer.Theleftsentinel'skeyissmaller,andtherightsentinel'skeyisgreater,thananykeythatmaybeaddedtotheset.Searchingtheskiplistthusalwaysbeginsattheleftsentinel.3OurAlgorithmWepresentourconcurrentskip-listalgorithminthecontextofanimplementa-tionofasetobjectsupportingthreemethods,add,removeandcontains:add(v)addsvtothesetandreturnstruei vwasnotalreadyintheset;remove(v)removesvfromthesetandreturnstruei vwasintheset;andcontains(v)returnstruei visintheset.Weshowthatourimplementationislinearizable[5];thatis,everyoperationappearstotakeplaceatomicallyatsomepoint(the2 33intfindNode(intv,34Nodepreds[],35Nodesuccs[])f36intlFound=1;37Nodepred=&LSentinel;38for(intlayer=MaxHeight1;39layer0;40layer)f41Nodecurr=pred�nexts[layer];42while(v�curr�key)f43pred=curr;curr=pred�nexts[layer];44g45if(lFound==1&&v==curr�key)f46lFound=layer;47g48preds[layer]=pred;49succs[layer]=curr;50g51returnlFound;52gFigure1.3.ThefindNodehelperfunctionsuccsofnodepointers,andsearchesexactlyasinasequentialskiplist,startingatthehighestlayerandproceedingtothenextlowerlayereachtimeitencountersanodewhosekeyisgreaterthanorequaltov.Thethreadrecordsinthepredsarraythelastnodewithakeylessthanvthatitencounteredateachlayer,andthatnode'ssuccessor(whichmusthaveakeygreaterthanorequaltov)inthesuccsarray.Ifit ndsanodewiththesought-afterkey,findNodereturnstheindexofthe rstlayeratwhichsuchanodewasfound;otherwise,itreturns1.Forsimplicityofpresentation,wehavefindNodecontinuetothebottomlayerevenifit ndsanodewiththesought-afterkeyatahigherlevel,soalltheentriesinbothpredsandsuccsarraysare lledinafterfindNodeterminates(seeSection3.4foroptimizationsusedintherealimplementation).NotethatfindNodedoesnotacquireanylocks,nordoesitretryincaseofcon\rictingaccesswithsomeotherthread.Wenowconsidereachoftheoperationsinturn.3.1TheaddoperationTheaddoperation,showninFigure1.4,callsfindNodetodeterminewhetheranodewiththekeyisalreadyinthelist.Ifso(lines59{66),andthenodeisnotmarked,thentheaddoperationreturnsfalse,indicatingthatthekeyisalreadyintheset.However,ifthatnodeisnotyetfullylinked,thenthethreadwaitsuntilitis(becausethekeyisnotintheabstractsetuntilthenodeisfullylinked).Ifthenodeismarked,thensomeotherthreadisintheprocessofdeletingthatnode,sothethreaddoingtheaddoperationsimplyretries.4 54booladd(intv)f55inttopLayer=randomLevel(MaxHeight);56Nodepreds[MaxHeight],succs[MaxHeight];57while(true)f58intlFound=findNode(v,preds,succs);59if(lFound=1)f60NodenodeFound=succs[lFound];61if(!nodeFound�marked)f62while(!nodeFound�fullyLinked)f;g63returnfalse;64g65continue;66g67inthighestLocked=1;68tryf69Nodepred,succ,prevPred=null;70boolvalid=true;71for(intlayer=0;72valid&&(layertopLayer);73layer++)f74pred=preds[layer];75succ=succs[layer];76if(pred=prevPred)f77pred�lock.lock();78highestLocked=layer;79prevPred=pred;80g81valid=!pred�marked&&!succ�marked&&82pred�nexts[layer]==succ;83g84if(!valid)continue;86NodenewNode=newNode(v,topLayer);87for(intlayer=0;88layertopLayer;89layer++)f90newNode�nexts[layer]=succs[layer];91preds[layer]�nexts[layer]=newNode;92g94newNode�fullyLinked=true;95returntrue;96g97finallyfunlock(preds,highestLocked);g98gFigure1.4.Theaddmethod5 Ifnonodewasfoundwiththeappropriatekey,thenthethreadlocksandvalidatesallthepredecessorsreturnedbyfindNodeuptotheheightofthenewnode(lines69{84).Thisheight,denotedbytopNodeLayer,isdeterminedattheverybeginningoftheaddoperationusingtherandomLevelfunction.3Validation(lines81{83)checksthatforeachlayeritopNodeLayer,preds[i]andsuccs[i]arestilladjacentatlayeri,andthatneitherismarked.Ifvalidationfails,thethreadencounteredacon\rictingoperation,soitreleasesthelocksitacquired(inthefinallyblockatline97)andretries.IfthethreadsuccessfullylocksandvalidatestheresultsoffindNodeuptotheheightofthenewnode,thentheaddoperationisguaranteedtosucceedbecausethethreadholdsallthelocksuntilitfullylinksitsnewnode.Inthiscase,thethreadallocatesanewnodewiththeappropriatekeyandheight,linksitin,setsthefullyLinked\ragofthenewnode(thisisthelinearizationpointoftheaddoperation),andthenreturnstrueafterreleasingallitslocks(lines86{97).ThethreadwritingnewNode-�nexts[i]istheonecaseinwhichathreadmodi esthenexts eldforanodeithasnotlocked.ItissafebecausenewNodewillnotbelinkedintothelistatlayeriuntilthethreadsetspreds[i]-�nexts[i]tonewNode,afteritwritesnewNode-�nexts[i].3.2TheremoveoperationTheremoveoperationshowninFigure1.5,likewisecallsfindNodetodeterminewhetheranodewiththeappropriatekeyisinthelist.Ifso,thethreadcheckswhetherthenodeis\okaytodelete"(Figure1.6),whichmeansitisfullylinked,notmarked,anditwasfoundatitstoplayer.4Ifthenodemeetstheserequire-ments,thethreadlocksthenodeandveri esthatitisstillnotmarked.Ifso,thethreadmarksthenode,whichlogicallydeletesit(lines111{121);thatis,themarkingofthenodeisthelinearizationpointoftheremoveoperation.Therestoftheprocedureaccomplishesthe\physical"deletion,removingthenodefromthelistby rstlockingitspredecessorsatalllayersuptotheheightofthedeletednode(lines124{138),andsplicingthenodeoutonelayeratatime(lines140{142).Tomaintaintheskip-liststructure,thenodeissplicedoutofhigherlayersbeforebeingsplicedoutoflowerones(though,toensurefreedomfromdeadlock,asdiscussedinSection4,thelocksareacquiredintheoppositeorder,fromlowerlayersup).Asintheaddoperation,beforechanginganyofthedeletednode'spredecessors,thethreadvalidatesthatthosenodesareindeedstillthedeletednode'spredecessors.ThisisdoneusingtheweakValidatefunction,whichisthesameasvalidateexceptthatitdoesnotfailifthesuccessor3ThisfunctionistakenfromLea'salgorithmtoensureafaircomparisonintheex-perimentspresentedinSection5.Itreturns0withprobability34,iwithprobability2(i+2)fori2[1;30],and31withprobability232.4Anodefoundnotinitstoplayerwaseithernotyetfullylinked,ormarkedandpartiallyunlinked,atsomepointwhenthethreadtraversedthelistatthatlayer.Wecouldhavecontinuedwiththeremoveoperation,butthesubsequentvalidationwouldfail.6 101boolremove(intv)f102NodenodeToDelete=null;103boolisMarked=false;104inttopLayer=1;105Nodepreds[MaxHeight],succs[MaxHeight];106while(true)f107intlFound=findNode(v,preds,succs);108if(isMarkedjj109(lFound=1&&okToDelete(succs[lFound],lFound)))f111if(!isMarked)f112nodeToDelete=succs[lFound];113topLayer=nodeToDelete�topLayer;114nodeToDelete�lock.lock();115if(nodeToDelete�marked)f116nodeToDelete�lock.unlock();117returnfalse;118g119nodeToDelete�marked=true;120isMarked=true;121g122inthighestLocked=1;123tryf124Nodepred,succ,prevPred=null;125boolvalid=true;126for(intlayer=0;127valid&&(layertopLayer);128layer++)f129pred=preds[layer];130succ=succs[layer];131if(pred=prevPred)f132pred�lock.lock();133highestLocked=layer;134prevPred=pred;135g136valid=!pred�marked&&pred�nexts[layer]==succ;137g138if(!valid)continue;140for(intlayer=topLayer;layer0;layer)f141preds[layer]�nexts[layer]=nodeToDelete�nexts[layer];142g143nodeToDelete�lock.unlock();144returntrue;145g146finallyfunlock(preds,highestLocked);g147g148elsereturnfalse;149g150gFigure1.5.Theremovemethod7 152boolokToDelete(Nodecandidate,intlFound)f153return(candidate�fullyLinked154&&candidate�topLayer==lFound155&&!candidate�marked);156gFigure1.6.TheokToDeletemethod158boolcontains(intv)f159Nodepreds[MaxHeight],succs[MaxHeight];160intlFound=findNode(v,preds,succs);161return(lFound=1162&&succs[lFound]�fullyLinked163&&!succs[lFound]�marked);164gFigure1.7.Thecontainsmethodismarked,sincethesuccessorinthiscaseshouldbethenodetoberemovedthatwasjustmarked.Ifthevalidationfails,thenthethreadreleasesthelocksontheoldpredecessors(butnotthedeletednode)andtriesto ndthenewpredecessorsofthedeletednodebycallingfindNodeagain.However,atthispointithasalreadysetthelocalisMarked\ragsothatitwillnottrytomarkanothernode.Aftersuccessfullyremovingthedeletednodefromthelist,thethreadreleasesallitslocksandreturnstrue.Ifnonodewasfound,orthenodefoundwasnot\okaytodelete"(i.e.,wasmarked,notfullylinked,ornotfoundatitstoplayer),thentheoperationsimplyreturnsfalse(line148).Itiseasytoseethatthisiscorrectifthenodeisnotmarkedbecauseforanykey,thereisatmostonenodewiththatkeyintheskiplist(i.e.,reachablefromtheleftsentinel)atanytime,andonceanodeisputinthelist(whichitmusthavebeentobefoundbyfindNode),itisnotremoveduntilitismarked.However,theargumentistrickierifthenodeismarked,becauseatthetimethenodeisfound,itmightnotbeinthelist,andsomeunmarkednodewiththesamekeymaybeinthelist.However,asweargueinSection4,inthatcase,theremusthavebeensometimeduringtheexecutionoftheremoveoperationatwhichthekeywasnotintheabstractset.3.3ThecontainsoperationFinally,weconsiderthecontainsoperation,showninFigure1.7,whichjustcallsfindNodeandreturnstrueifandonlyifit ndsaunmarked,fullylinkednodewiththeappropriatekey.Ifit ndssuchanode,thenitisimmediatefromthede nitionthatthekeyisintheabstractset.However,asmentionedabove,ifthenodeismarked,itisnotsoeasytoseethatitissafetoreturnfalse.WearguethisinSection4.8 3.4ImplementationIssuesWeimplementedthealgorithmintheJavaTMprogramminglanguage,inor-dertocompareitwithDougLea'snonblockingskip-listimplementationinthejava.util.concurrentpackage.Thearraystackvariablesinthepseudocodearereplacedbythread-localvariables,andweusedastraightforwardlockimple-mentation(wecouldnotusethebuilt-inobjectlocksbecauseouracquireandreleasepatterncouldnotalwaysbeexpressedusingsynchronizedblocks).Thepseudocodepresentedwasoptimizedforsimplicity,noteciency,andtherearenumerousobviouswaysinwhichitcanbeimproved,manyofwhichweappliedtoourimplementation.Forexample,ifanodewithanappropriatekeyisfound,theaddandcontainsoperationsneednotlookfurther;theyonlyneedtoascertainwhetherthatnodeisfullylinkedandunmarked.Ifso,thecontainsoperationcanreturntrueandtheaddoperationcanreturnfalse.Ifnot,thenthecontainsoperationcanreturnfalse,andtheaddoperationeitherwaitsbeforereturningfalse(ifthenodeisnotfullylinked)orelsemustretry.Theremoveoperationdoesneedtosearchtothebottomlayerto ndallthepredecessorsofthenodetobedeleted,however,onceit ndsandmarksthenodeatsomelayer,itcansearchforthatexactnodeatlowerlayersratherthancomparingkeys.5Thisiscorrectbecauseonceathreadmarksanode,nootherthreadcanunlinkit.Also,inthepseudocode,findNodealwaysstartssearchingfromthehighestpossiblelayer,thoughweexpectmostofthetimethatthehighestlayerswillbeempty(i.e.,haveonlythetwosentinelnodes).Itiseasytomaintainavari-ablethattracksthehighestnonemptylayerbecausewheneverthatchanges,thethreadthatcausesthechangemusthavetheleftsentinellocked.Thiseaseisincontrasttothenonblockingversion,inwhicharacebetweenconcurrentremoveandaddoperationsmayresultintherecordedheightoftheskiplistbeinglessthantheactualheightofitstallestnode.4CorrectnessInthissection,wesketchaproofforourskip-listalgorithm.Therearefourpropertieswewanttoshow:thatthealgorithmimplementsalinearizableset,thatitisdeadlock-free,thatthecontainsoperationiswait-free,andthattheunderlyingdatastructuremaintainsacorrectskip-liststructure,whichwede nemorepreciselybelow.4.1LinearizabilityFortheproof,wemakethefollowingsimplifyingassumptionaboutinitialization:Nodesareinitializedwiththeirkeyandheight,theirnextsarraysareinitializedtoallnull,andtheirfullyLinkedandmarked eldsareinitializedtofalse.5Comparingkeysisexpensivebecause,tomaintaincompatibilitywithLea'simple-mentation,comparisoninvokesthecompareTomethodoftheComparableinterface.9 Furthermore,weassumeforthepurposesofreasoningthatnodesareneverreclaimed,andthereisaninexhaustiblesupplyofnewnodes(otherwise,wewouldneedtoaugmentthealgorithmtohandlerunningoutofnodes).We rstmakethefollowingobservations:Thekeyofanodeneverchanges(i.e.,key=kisstable),andthemarkedandfullyLinked eldsofanodeareneversettofalse(i.e.,markedandfullyLinkedarestable).Thoughinitiallynull,nexts[i]isneverwrittentonull(i.e.,nexts[i]=nullisstable).Also,athreadwritesanode'smarkedornexts eldsonlyifitholdsthenode'slock(withtheoneexceptionofanaddoperationwritingnexts[i]ofanodebeforelinkingitinatlayeri).Fromtheseobservations,andbyinspectionofthecode,itiseasytoseethatinanyoperation,aftercallingfindNode,wehavepreds[i]-�keyvandsuccs[i]-�.87;挡keyvforalli,andsuccs[i]-�.87;挡key�.87;挡vfori�.87;挡lFound(thevaluereturnedbyfindNode).Also,forathreadinremove,nodeToDeleteisonlysetonce,andthatunlessthatnodewasmarkedbysomeotherthread,thisthreadwillmarkthenode,andthereafter,untilitcompletestheoperation,thethread'sisMarkedvariablewillbetrue.WealsoknowbyokToDeletethatthenodeisfullylinked(andindeedthatonlyfullylinkednodescanbemarked).Furthermore,validationandtherequirementtolocknodesbeforewritingthemensuresthataftersuccessfulvalidation,thepropertiescheckedbytheval-idation(whichareslightlydi erentforaddandremove)remaintrueuntilthelocksarereleased.Wecanusethesepropertiestoderivethefollowingfundamentallemma:Lemma1.Foranodenand0in-�.87;挡topLayer:n-�.87;挡nexts[i]=null=)n-�.87;挡keyn-&#x-276;&#x.153;nexts[i]-&#x-276;&#x.153;keyWede netherelation!isothatm!in(read\mleadstonatlayeri")ifm-&#x-276;&#x.153;nexts[i]=northereexistsm0suchthatm!im0andm0-&#x-276;&#x.153;nexts[i]=n;thatis,!iisthetransitiveclosureoftherelationthatrelatesnodestotheirimmediatesuccessorsatlayeri.Becauseanodehas(atmost)oneimmediatesuccessoratanylayer,the!irelation\follows"alinkedlistatlayeri,andinparticular,thelayer-ilistoftheskiplistconsistsofthosenodesnsuchthatLSentinel!in(plusLSentinelitself).Also,byLemma1,ifm!inandm!in0andn-&#x-276;&#x.153;keyn0-&#x-276;&#x.154;keythenn!in0.Usingtheseobservations,wecanshowthatifm!ininanyreachablestateofthealgorithm,thenm!ininanysubsequentstateunlessthereisanactionthatsplicesnoutofthelayer-ilist,thatis,anexecutionofline141.Thisclaimisprovedformallyforthelazy-listalgorithminarecentpaper[1],andthatproofcanbeadaptedtothisalgorithm.Becausenmustalreadybemarkedbeforebeingsplicedoutofthelist,andbecausethefullyLinked\ragisneversettofalse(afteritsinitialization),thisclaimimpliesthatakeycanberemovedfromtheabstractsetonlybymarkingitsnode,whichwearguedearlieristhelinearizationpointofasuccessfulremoveoperation.Similarly,wecanseethatifLSentinel!indoesnotholdinsomereachablestateofthealgorithm,thenitdoesnotholdinanysubsequentstateunlessthere10 issomeexecutionofline91withn=newNode(asdiscussedearlier,thepreviouslinedoesn'tchangethelistatlayer-ibecausenewNodeisnotyetlinkedinthen).However,theexecutionofthatlineoccurswhilenewNodeisbeinginsertedandbeforenewNodeisfullylinked.Thus,theonlyactionthataddsanodetoalistatanylevelisthesettingofthenode'sfullyLinked\rag.Finally,wearguethatifathread ndsamarkednodethenthekeyofthatnodemusthavebeenabsentfromthelistatsomepointduringtheexecutionofthethread'soperation.Therearetwocases:Ifthenodewasmarkedwhenthethreadinvokedtheoperation,thenodemusthavebeenintheskiplistatthattimebecausemarkednodescannotbeaddedtotheskiplist(onlyanewlyallocatednodecanbeaddedtotheskiplist),andbecausenotwonodesintheskiplistcanhavethesamekey,nounmarkednodeintheskiplisthasthatkey.Thus,attheinvocationoftheoperation,thekeyisnotintheskiplist.Ontheotherhand,ifthenodewasnotmarkedwhenthethreadinvokedtheoperation,thenitmusthavebeenmarkedbysomeotherthreadbeforethe rstthreadfoundit.Inthiscase,thekeyisnotintheabstractsetimmediatelyaftertheotherthreadmarkedthenode.Thisclaimisalsoprovedformallyforthesimplelazylist[1],andthatproofcanbeadaptedtothisalgorithm.4.2Maintainingtheskip-liststructureOuralgorithmguaranteesthattheskip-liststructureispreservedatalltimes.By\skip-liststructure",wemeanthatthelistateachlayerisasublistofthelistsatlowerlayers.Itisimportanttopreservethisstructure,asthecomplexityanalysisforskiplistsrequiresthisstructure.Toseethatthealgorithmpreservestheskip-liststructure,notethatlinkingnewnodesintotheskiplistalwaysproceedsfrombottomtotop,andwhileholdingthelocksonallthesoon-to-bepredecessorsofthenodebeinginserted.Ontheotherhand,whenanodeisbeingremovedfromthelist,thehigherlayersareunlinkedbeforethelowerlayers,andagain,whileholdinglocksonalltheimmediatepredecessorsofthenodebeingremoved.Thispropertyisnotguaranteedbythelock-freealgorithm.Inthatalgorithm,afterlinkinganodeinthebottomlayer,linksthenodeintherestofthelayersfromtoptobottom.Thismayresultinastateofanodethatislinkedonlyinitstopandbottomlayers,sothatthelistatthetoplayerisnotasublistofthelistatthelayerimmediatelybeneathit,forexample.Moreover,attemptstolinkinanodeatanylayerotherthanthebottomarenotretried,andhencethisstateofnonconformitytotheskip-liststructuremaypersistinde nitely.4.3Deadlockfreedomandwait-freedomThealgorithmisdeadlock-freebecauseathreadalwaysacquireslocksonnodeswithlargerkeys rst.Moreprecisely,ifathreadholdsalockonanodewithkeyvthenitwillnotattempttoacquirealockonanodewithkeygreaterthanorequaltov.Wecanseethatthisistruebecauseboththeaddandremovemethodsacquirelocksonthepredecessornodesfromthebottomlayerup,and11 SunFireTMT2000SunEnterpriseTM6500Operations: 9% add, 1% remove, 90% containsRange: 200,000500100015002000250030003500400045005000020406080ThreadsThroughputLazyLeaSeqOperations: 9% add, 1% remove, 90% containsRange: 200,00050010001500200025003000020406080ThreadsThrougputLazyLeaSeqOperations: 9% add, 1% remove, 90% containsRange: 2,000,000500100015002000250030003500020406080ThreadsThroughputLazyLeaSeqOperations: 9% add, 1% remove, 90% containsRange: 2,000,000200400600800100012001400020406080ThreadsThrougputLazyLeaSeqFig.8.Throughputinoperationspermillisecondof1,000,000operations,with9%add,1%remove,and90%containsoperations,andarangeofeither200,000or2,000,000.thekeyofapredecessornodeislessthanthekeyofadi erentpredecessornodeatalowerlayer.Theonlyotherlockacquisitionisforthenodethataremoveoperationdeletes.Thisisthe rstlockacquiredbythatoperation,anditskeyisgreaterthanthatofanyofitspredecessors.Thatthecontainsoperationiswait-freeisalsoeasytosee:itdoesnotacquireanylocks,nordoesiteverretry;itsearchesthelistonlyonce.5PerformanceWeevaluatedourskip-listalgorithmbyimplementingintheJavaprogramminglanguage,asdescribedearlier.WecomparedourimplementationagainstDougLea'snonblockingskip-listimplementationintheConcurrentSkipListMapclassofthejava.util.concurrentpackage,whichispartoftheJavaTMSE6plat-form;toourknowledge,thisisthebestwidelyavailableconcurrentskip-listimplementation.Wealsoimplementedastraightforwardsequentialskiplist,inwhichmethodsweresynchronizedtoensurethreadsafety,foruseasabaselineintheseexperiments.Wedescibesomeoftheresultsweobtainedfromtheseexperimentsinthissection.12 SunFireTMT2000SunEnterpriseTM6500Operations: 20% add, 10% remove, 70% containsRange: 200,00050010001500200025003000350040004500010203040506070ThreadsThroughputLazyLeaSeqOperations: 20% add, 10% remove, 70% containsRange: 200,0005001000150020002500020406080ThreadsThrougputLazyLeaSeqOperations: 20% add, 10% remove, 70% containsRange: 2,000,00050010001500200025003000020406080ThreadsThroughputLazyLeaSeqOperations: 20% add, 10% remove, 70% containsRange: 2,000,00020040060080010001200020406080ThreadsThrougputLazyLeaSeqFig.9.Throughputinoperationspermillisecondof1,000,000operationswith20%add,10%remove,and70%containsoperations,andrangeofeither200,000or2,000,000.Wepresentresultsfromexperimentsontwomultiprocessorsystemswithquitedi erentarchitectures.The rstsystemisaSunFireTMT2000server,whichisbasedonasingleUltraSPARCR\rT1processorcontainingeightcom-putingcores,eachwithfourhardwarestrands,clockedat1200MHz.Eachfour-strandcorehasasingle8-KBytelevel-1datacacheandasingle16-KBytein-structioncache.Alleightcoresshareasingle3-MBytelevel-2uni ed(instructionanddata)cache,andafour-wayinterleaved32-GBytemainmemory.Dataac-cesslatencyratiosareapproximately1:8:50forL1:L2:Memoryaccesses.TheothersystemisanolderSunEnterpriseTM6500server,whichcontains15sys-temboards,eachwithtwoUltraSPARCR\rIIprocessorsclockedat400MHzand2GbytesofRAMforatotalof30processorsand60GbytesofRAM.Eachprocessorhasa16-KBytedatalevel-1cacheanda16-Kbyteinstructioncacheonchip,anda8-MByteexternalcache.Thesystemclockfrequencyis80MHz.Wepresentresultsfromexperimentsinwhich,startingfromanemptyskiplist,eachthreadexecutesonemillion(1,000,000)randomlychosenoperations.Wevariedthenumberofthreads,therelativeproportionofadd,removeandcontainsoperations,andtherangefromwhichthekeyswereselected.Thekeyforeachoperationwasselecteduniformlyatrandomfromthespeci edrange.13 SunFireTMT2000SunEnterpriseTM6500Operations: 50% add, 50% remove, 0% containsRange: 200,0005001000150020002500300035004000020406080ThreadsThroughputLazyLeaOperations: 50% add, 50% remove, 0% containsRange: 200,000200400600800100012001400020406080ThreadsThrougputLazyLeaFig.10.Throughputinoperationspermillisecondof1,000,000operations,with50%addand50%removeoperations,andarangeof200,000Inthegraphsthatfollow,wecomparethethroughputinoperationspermillisecond,andtheresultsshownaretheaverageoversixrunsforeachsetofparameters.Figure8presentstheresultsofexperimentsinwhich9%oftheoperationswereaddoperations,1%wereremoveoperations,andtheremaining90%werecontainsoperations,wheretherangeofthekeyswaseithertwohundredthou-sandortwomillion.Thedi erentrangesgivedi erentlevelsofcontention,withsigni cantlyhighercontentionwiththe200,000range,comparedwiththe2,000,000range.Aswecanseefromtheseexperiments,bothourimplementationandLea'sscalewell(andthesequentialalgorithm,asexpected,isrelatively\rat).Inallbutonecase(with200,000rangeontheoldersystem),ourimplementationhasaslightadvantage.Inthenextsetofexperiments,weranwithhigherpercentagesofaddandremoveoperations,20%and10%respectively(leaving70%containsopera-tions).TheresultsareshowninFigure9.Ascanbeseen,ontheT2000system,thetwoimplementationshavesimilarperformance,withaslightadvantagetoLeainamultiprogrammedenvironmentwhentherangeissmaller(highercon-tention).Thesituationisreversedwiththelargerrange.Thisphenomenonismorenoticeableontheoldersystem:thereweseea13%advantagetoLea'simplementationonthesmallerrangewith64threads,and20%advantagetoouralgorithmwiththesamenumberofthreadswhentherangeislarger.Toexplorethisphenomenon,weconductedanexperimentwithasigni cantlyhigherlevelofcontention:halfaddoperationsandhalfremoveoperationswitharangeof200,000.TheresultsarepresentedinFigure10.Ascanbeclearlyseen,underthislevelofcontention,ourimplementation'sthroughputdegradesrapidlywhenapproachingthemultiprogrammingzone,especiallyontheT2000system.Thisdegradationisnotsurprising:Inourcurrentimplementation,whenanaddorremoveoperationfailsvalidation,orfailstoacquirealockimmediately,itsimplycallsyield;thereisnopropermechanismformanagingcontention.14 Sincetheaddandremoveoperationsrequirethatthepredecessorsseenduringthesearchphasebeunchangeduntiltheyarelocked,weexpectthatunderhighcontention,theywillrepeatedlyfail.Thus,weexpectthataback-o mechanism,orsomeothermeansofcontentioncontrol,wouldgreatlyimproveperformanceinthiscase.Toverifythatahighlevelofcon\rictisindeedtheproblem,weaddedcounterstocountthenumberofretriesexecutedbyeachthreadduringtheexperiment.Thecountersindeedshowthatmanyretriesareexecutedona64threadsrun,especiallyontheT2000.Mostoftheretriesareexecutedbytheaddmethod,whichmakessensebecausetheremovemethodmarksthenodetoberemovedbeforesearchingitspredecessorsinlowerlayers,whichpreventschangeofthesepredecessor'snextpointersbyaconcurrentaddoperation.6ConclusionsWehaveshownhowtoconstructascalable,highlyconcurrentskiplistusingaremarkablysimplealgorithm.Theprincipalopenquestioniswhetherwecanimprovethealgorithm'sperformanceathighlevelsofcontention.Onesimpleapproachistouseamoresophisticatedback-o schemewhensynchronizationcon\rictsaredetected.Anotherintriguingapproachistoallowtherandomnessoftheskip-list'sheighttobecompromisedunderhighcontention.Inthealgorithmpresentedhere,whenathreadaddsanewitem,itgivesupandretriesifitencountersasynchronizationcon\rictwhenlinkingtheitematanylevel.Inprinciple,athreadthatencountersacon\rictwhenlinkingtheitematlayer`�0couldsimplystopthere,leavingtheitemlinkedatlevelszeroto`1,actingasifithadrandomlychosen`1.Theresultingdatastructure,whilestructurallystillaskiplist,wouldbealittle\ratterthanitshouldbe.Whetherthisapproachise ectiveisthesubjectoffuturework.References1.Colvin,R.,Groves,L.,Luchangco,V.,andMoir,M.Formalveri cationofalazyconcurrentlist-basedset.InProceedingsofComputer-AidedVeri cation(Aug.2006).2.Fraser,K.PracticalLock-Freedom.PhDthesis,UniversityofCambridge,2004.3.Heller,S.,Herlihy,M.,Luchangco,V.,Moir,M.,Shavit,N.,andSchererIII,W.N.Alazyconcurrentlist-basedsetalgorithm.InProceedingsof9thInternationalConferenceonPrinciplesofDistributedSystems(Dec.2005).4.Herlihy,M.,Luchangco,V.,andMoir,M.Therepeato enderproblem:Amechanismforsupportingdynamic-sized,lock-freedatastructures.InProceedingsofDistributedComputing:16thInternationalConference(2002).5.Herlihy,M.,andWing,J.Linearizability:Acorrectnessconditionforconcurrentobjects.ACMTransactionsonProgrammingLanguagesandSystems12,3(July1990),463{492.6.Michael,M.Hazardpointers:Safememoryreclamationforlock-freeobjects.IEEETransactionsonParallelandDistributedSystems15,6(June2004),491{504.7.Pugh,W.Skiplists:Aprobabilisticalternativetobalancedtrees.CommunicationsoftheACM33,6(June1990),668{676.15