2æ27ã28æ¥ã«éå¬ãããæåã®C ++ 2015ãã·ã¢äŒè°ã§è¬æŒããããæåŸ ãããããšãå æ ã«æããŸãã ç§ã¯éåžžã«wasæ ¢ã ã£ãã®ã§ãæ¬æ¥ããã¹ããã®ã®ä»£ããã«2æé話ãããã«é Œã¿ãæãèå³ã®ãããããã¯ã§ãã競äºåã®ããé£æ³ã³ã³ããã«ã€ããŠè¿°ã¹ãŸããã ãããã¯ãããã·ã¥ã»ãã/ãããããã³ããªãŒã§ãã ãªãŒã¬ãã€ã¶ãŒsermpã¯åé²ããŸããã
ãã®ãããªå°é£ãª
ãã¡ãããã¹ã©ã€ããèŠãŠãèããæžãçããå¿ èŠããããŸãã ãããŠãäœããæžãããŠããã°ãå ¬éããã®ã¯æªããªãã§ãããã ãããŠãããªããå ¬éãããªããããã§
ã ããã C ++ 2015ãã·ã¢ããã£ããã«ïŒ èè ã®ãã¬ãŒã³ããŒã·ã§ã³ã¯ãèè ã®èã«çžãããèããªããããã€ãã®éšåã§ã€ãã³ãã®åã«æžããããããã¯ã®ã«ãããéžè±ããªãããšãé¡ã£ãŠããŸãã
C ++ããã°ã©ããšããŠãã³ã³ãã/ã©ã€ãã©ãª/ã¹ã¿ãã¯/ããã/ãªã¹ãã§ã¯ãªããé£æ³ã³ã³ãã-ããã·ã¥ã»ãã/ããããstd :: unordered_set / mapãtreesãã€ãŸãstd ::ã䜿çšããªããã°ãªããªãã£ãã³ã³ããã®æšæºã©ã€ãã©ãªã®ã»ãšãã©ãã¹ãŠã»ãã/ãããã ãåãã®ããã«ãC ++ 11æšæºã§ã¯ããã®ãããªã³ã³ããã§ã®ã¹ã¬ããã»ãŒããªåäœãä¿èšŒãããŠããŸãããéåžžã«åŒ±ã-èªã¿åãå°çšã§ãå€æŽã¯ãã¹ãŠ-å€éšããã¯ã§ã®ã¿å¯èœã§ãïŒ å®éã«ã¯ããã®ãããªä¿èšŒã¯ã»ãšãã©ãããŸãããèªã¿åãå°çšããããããå ŽåããœãŒããããé åãäœæãããã€ããªæ€çŽ¢ã䜿çšããŠæ€çŽ¢ããå¯èœæ§ãé«ãããã§ããããã
å€éšåæãå¿ èŠãšããã«äžŠè¡ãããã³ã³ãããå®è£ ããããšã¯å¯èœã§ããïŒ ãã®è³ªåãå匷ããŸãããã
ãŠã©ãŒã ã¢ããããããã«ãããã·ã¥ãããã®å éšæ§é ãèŠãŠã¿ãŸãããã
ããã·ã¥ããŒãã«
è¡çªã®ãªã¹ããæã€æãåçŽãªããã·ã¥ãããã®å éšæ§é ã¯éåžžã«åå§çã§ããé å
T[N]
ããã®åèŠçŽ ã¯ãªã¹ãã§ãã ããŒãã«ãžã®ãšã³ããªïŒã€ã³ããã¯ã¹ïŒã¯ãããŒã®ããã·ã¥å€ã§ãã åãããã·ã¥ïŒã¢ãžã¥ã
N
ïŒãæã€ãã¹ãŠã®ããŒã¯ãè¡çªãªã¹ããšåŒã°ããåããªã¹ãã«åé¡ãããŸãã
äžè¬çã«ãããã§æãéèŠãªããšã¯ããã·ã¥é¢æ°ã®äžã«é ãããŠããŸãã å€ãã®ããŒã«å¯ŸããŠæ£ããããã·ã¥é¢æ°ãéžæãããŠããå Žåã«ã®ã¿ãããã·ã¥ãããã¯é©åã«æ©èœããŸãã ãä¿®æ£ã-ããã¯ããŸã第äžã«ãè¡šã®ã»ã«å ã®ãååã«åæ£ãããããŒãæå³ããŸãã ãããã競äºã®ã¬ãã«ãé«ãããšãã芳ç¹ããã¯ãããã·ã¥é¢æ°ãå éšã«ã©ã®ããã«é 眮ãããŠãããã¯åé¡ã§ã¯ãªãããããã以äžèª¬æããŸããã
åçãèŠããšãéåžžã®ããã·ã¥ãããã競åãããæ¹æ³ãããã«æšæž¬ã§ããŸããããã·ã¥ãããå šäœãžã®ã¢ã¯ã»ã¹ããããã¯ãã代ããã«ãããŒãã«
T[N]
ã®åã»ã«ã®ã¬ãã«ã§ãããã¯ã§ããŸãã ãããã£ãŠãè¡çª
T[i]
ç¹å®ã®åãªã¹ãã§ã®äœæ¥ã¯ã·ãªã¢ã«åãããŸãããç°ãªããªã¹ã
T[i]
ããã³
T[j]
ïŒ
i != j
ïŒã§ã®äœæ¥ã¯äžŠè¡ããŠå®è¡ã§ããŸãã ãã®ææ³ã¯ã MãHerlihyããã³Nir Shavitã®The Art of Multiprocessor Programmingã§èª¬æãããŠãããã¹ãã©ã€ãã³ã°ãšåŒã°ããŸãã
ãããªãã·ã£ãŒã®äž»åŒµ
ãªãªãžãã«ã§ã¯ãã§ã«2ã€ã®ãšãã£ã·ã§ã³ããããŸããããªããã®äœåã¯ãŸã 翻蚳ãããŠããªãã®ã§ããïŒïŒ äžçã®èåãªäœå®¶ã«ãããã®åºæ¬çãªäœåã¯ãã¯ããŒãã®èšå¿µç¢çãªã¢ãã°ã©ãã«é¡äŒŒããŠããŸããã䞊åã¢ã«ãŽãªãºã ã«ãšã£ãŠã¯ãåŠçããä»çµã¿ããç解ããããã¹ãŠã®äººã«ãšã£ãŠéåžžã«è²Žéãªã¬ã€ãã§ãããåœå
ã®äººæè²æã®åºçºç¹ã§ãã
ããããå€çŽããããŒã®ããã«35åã§C ++ããçºè¡ããŸãïŒ ãããŒã¯C ++ãå¿ èŠãšããŸãã!!! ãã®ãããªæ¬ããªããã°ããã£ãŒããããããããŸããã ãã®å 責äºé ã¯ãhabrã®èªè ã«ã¯é¢ä¿ãããŸããã
ããããå€çŽããããŒã®ããã«35åã§C ++ããçºè¡ããŸãïŒ ãããŒã¯C ++ãå¿ èŠãšããŸãã!!! ãã®ãããªæ¬ããªããã°ããã£ãŒããããããããŸããã ãã®å 責äºé ã¯ãhabrã®èªè ã«ã¯é¢ä¿ãããŸããã
çžæš¡æ§ã®å°å³
ãããã£ãŠãã¹ãã©ã€ãã³ã°ææ³ã§ã¯ã
Lock[N]
é åãš
T[N]
ããã·ã¥ããŒãã«èªäœã®2ã€ã®é åããããŸãã æåã¯ãããã2ã€ã®é åã®ãµã€ãºã¯åãã§ãïŒããã¯éèŠãªèŠä»¶ã§ãããåŸã§èª¬æããŸãïŒã æäœã®å éšã¢ã«ãŽãªãºã ã¯åçŽã§ããä»»æã®æäœïŒæ¿å ¥/æ¶å»/æ€çŽ¢ïŒã§ã
N
æ³
i
ããŒã®ããã·ã¥å€
i
ãèšç®ãã
Lock[i]
ãã¥ãŒããã¯ã¹ã
Lock[i]
ãããªã¹ã
T[i]
æäœãå®è¡ããŸãã ãããã1ã€ã®ãããããããããŸããããã·ã¥ããŒãã«ã¯æã æ¡åŒµããå¿ èŠããããŸãã æ¡åŒµã®å¿ èŠæ§ã®åºæºã¯ãããããè² è·ä¿æ°ã§ãïŒããã·ã¥ãããã®èŠçŽ æ°ãšããã·ã¥ããŒãã«ã®ãµã€ãº
N
æ¯çã ããŒãã«ãå±éããªãå Žåãã³ãªãžã§ã³ãªã¹ãã¯éåžžã«å€§ãããªããããã·ã¥ãããã®ãã¹ãŠã®å©ç¹ã¯ã«ããã£ã«å€ãããŸãïŒæäœã®è€éãã«ã€ããŠOïŒ1ïŒãè©äŸ¡ãã代ããã«ãOïŒS / NïŒãååŸããŸããSã¯ããŒãã«å ã®èŠçŽ ã®æ°ã§ãã S >> Nããã³å®æ°Nã®å ŽåãOïŒSïŒãã€ãŸãç·åœ¢æ€çŽ¢ã®è€éããšåçã§ãã ããã¯åãå ¥ããããŸããã ãã®çŸè±¡ã«å¯ŸåŠããã«ã¯ãåããã·ã¥ãå¿ èŠã§ããè² è·ä¿æ°ããããããå€ãè¶ ããå Žåã¯Nãå¢ãããæ°ããããã·ã¥å€
std::hash(key) % N'
ããã·ã¥ããŒãã«ãåæ§ç¯ããŸãã
ã¹ãã©ã€ããããã®åããã·ã¥ã¢ã«ãŽãªãºã ã¯æ¬¡ã®ãšããã§ãã
ãŸãããã¹ãŠã®ãã¥ãŒããã¯ã¹ãå·Šããå³ã«ããã¯ããŸãã 次ã«ãNãæŽæ°åå¢ãããŸãïŒæŽæ°ãéèŠã§ãã以äžãåç §ïŒãããã·ã¥ããŒãã«ãåæ§ç¯ããæåŸã«ããã¹ãŠã®ãã¥ãŒããã¯ã¹ãå³ããå·Šãžéé ã«ã¢ã³ããã¯ããŸãã ãããããã¯ã®äž»ãªçç±ã¯ãããã€ãã®ãã¥ãŒããã¯ã¹ã®ããã¯/ããã¯è§£é€é åºãéµå®ããªãããšã§ããããšãå¿ããªãã§ãã ããã
ããã§ãã¹ãŠã®ãã¥ãŒããã¯ã¹ãããã¯ããããšã¯éèŠã§ãã åããã·ã¥ã¯ããªãé£ããæäœã§ãããæ°ããããŒãã«
T[N']
ã®ã»ã«éã§ããŒãåé åžããŸãã
äžèšã®ããã·ã¥ããŒãã«ã®ãµã€ãºãå¢ããããšã«ã€ããŠè©±ããŸãããã
Lock[N]
é åã®ãµã€ãºãå¢ããããšã«ã€ããŠã¯äœãèšããªãã£ãããšã«æ³šæããŠãã ãã-ããã¯å¶ç¶ã§ã¯ãããŸãããäºå®ã¯ããã¯é åã®ãµã€ãºãå€ãããªããšããããšã§ãã
Lock
é åãš
T
é åã®ãµã€ãºãç°ãªãå Žåãååãšã㊠ãåãã»ã«
T[k]
ãç°ãªã
Lock[i]
ããã³
Lock[j]
ãã¥ãŒããã¯ã¹ã«å¯Ÿå¿ããå Žåãç¶æ³ã¯å¯èœã§ãã ãããåãå ¥ããããªãããã«ã¯ã次ã®ããšãå¿ èŠã§ãã
- æåã¯ã
Lock
é åãšT
é åã®ãµã€ãºã¯äžèŽããN
çãããªããŸã - åããã·ã¥ãããšã
N'
é åT
ã®æ°ãããµã€ãºN'
N' = k * N
ãšããŠèšç®ãããŸããããã§ãk
ã¯èªç¶æ°ïŒéåžžã¯2ïŒã§ãã
ãããã®æ¡ä»¶äžã§ã¯ãé å
T
ãµã€ãºã¯åžžã«
Lock
é åã®ãµã€ãºã®åæ°ã§ãïŒå€æŽãããŸããïŒã ç®è¡ã¢ãžã¥ãã®ç¹æ§ã«åºã¥ããŠããã®å Žåãåãã»ã«
T[k]
ãç°ãªã
Lock[i]
ããã³
Lock[j]
ãã¥ãŒããã¯ã¹ã«å¯Ÿå¿ã§ããªãããšã蚌æããã®ã¯ç°¡åã§ãã
æŽç·Žãããããã·ã¥ããã
ããã«ãããã»ããµããã°ã©ãã³ã°ã®æè¡ãã®èè
ã¯ã
é åã®åããã·ã¥ã¿ã¹ã¯ã解決ããããšãã€ãŸããããã·ã¥ããŒãã«ã®å¢å ãšãšãã«
ãµã€ãºãå¢å ã§ããã¢ã«ãŽãªãºã ãææ¡ããããšã«ãããããã«é²ãã§ããŸãã 圌ãã¯ãã®ã¢ã«ãŽãªãºã ã粟補å¯èœãªããã·ã¥ããããšåŒã³ãŸãã ãªãªãžãã«ãžã®éä¿¡ã«èå³ããããŸãã
Lock
é åã®åããã·ã¥ã¿ã¹ã¯ã解決ããããšãã€ãŸããããã·ã¥ããŒãã«ã®å¢å ãšãšãã«
Lock[]
ãµã€ãºãå¢å ã§ããã¢ã«ãŽãªãºã ãææ¡ããããšã«ãããããã«é²ãã§ããŸãã 圌ãã¯ãã®ã¢ã«ãŽãªãºã ã粟補å¯èœãªããã·ã¥ããããšåŒã³ãŸãã ãªãªãžãã«ãžã®éä¿¡ã«èå³ããããŸãã
ã¹ãã©ã€ãã³ã°ã¢ã«ãŽãªãºã ã¯ãããªãŒãªã©ã®ä»ã®ããŒã¿æ§é ã«ç°¡åã«æ¡åŒµã§ããŸãã
èãæ¹ã¯éåžžã«åçŽã§ã
Lock[L]
mutexé åã®åèŠçŽ ã¯ãã®ããªãŒãä¿è·ããŸãã
Lock[L]
ãžã®å ¥åã¯ãããŒã®ããã·ã¥å€ïŒã¢ãžã¥ã
L
ïŒã§ãã ããã¯
Lock[i]
ãããšã察å¿ããããªãŒã«ã¢ã¯ã»ã¹ããå¿ èŠãªã¢ã¯ã·ã§ã³ãå®è¡ããŸãã
libcds
libcdsã©ã€ãã©ãªã«ã¯ãã¹ãã©ã€ãåããæŽç·Žãããããã·ã¥ã»ãã/ãããã®å®è£
ãšãSTLããã³boostããã®ãã¹ãŠã®é£æ³ã³ã³ããïŒäŸµå
¥åãå«ãïŒã®ã¢ããã¿ãå®è£
ãããŠããŸãã
ã¹ãã©ã€ãã³ã°æè¡ã¯æªããããŸããããããã¯ããªãŒã®ããŒã¿æ§é ã«é¢ããäžé£ã®èšäºã«é¢ããŠé倧ãªæ¬ é¥ããããŸã-ãããã¯å¯èœã§ãã ããã·ã¥ãããã®ããã¯ããªãŒã¢ã«ãŽãªãºã ãèãåºãããšã¯å¯èœã§ããïŒ..
ããã¯ããªãŒã®é åºä»ããªã¹ã
ããã·ã¥ãããã®å éšæ§é ãããäžåºŠèŠãŠã¿ãŸãããã
åããã·ã¥ã®è³ªåãæ®ããŠããéããããã·ã¥ããŒãã«å ã®èŠçŽ ã®æ°ãã¢ããªãªãªã«ç¥ã£ãŠããŠãããŒã®ã»ããã«å¯ŸããŠé©åãªããã·ã¥é¢æ°ãæã£ãŠãããšä»®å®ããŸãã 次ã«ãããã¯ããªãŒããã·ã¥ããããäœæããã«ã¯ãããã¯ã®ãªãè¡çªã®ãªã¹ããå°ãå¿ èŠã§ãã è¡çªã®ãªã¹ãã¯ãé åºä»ããããïŒããŒã«ããïŒåçŽã«æ¥ç¶ããããªã¹ãã«ãããŸããã T. HarrisãšM. Michaelã®åŸããããæ§ç¯ããããšããŸãã
ããã¯ããªãŒãªã¹ãã®æ€çŽ¢ã¯éåžžã«ç°¡åã§ãããªã¹ãã®å é ããé ã«çŽç·çã«ãŠã©ãŒã¯ã¹ã«ãŒããŸãã ã¢ãããã¯æäœãšå®å šãªåé€ã¹ããŒã ïŒãã¶ãŒããã€ã³ã¿ãŒã ãŠãŒã¶ãŒã¹ããŒã¹RCUãªã©ïŒã®1ã€ã䜿çšããããšãèãããšãæ€çŽ¢ã¢ã«ãŽãªãºã ã¯é åºä»ããªã¹ãã§ã®éåžžã®æ€çŽ¢ãšããã»ã©å€ãããŸããïŒå®éãã³ãŒããèŠããšåŒ·åã§ãããããã¯ããã¯ããªãŒã®æéã§ãïŒã
æ°ããèŠçŽ ãæ¿å ¥ããããšãåé¡ã§ã¯ãããŸããã
æ¿å ¥äœçœ®ãæ¢ãïŒé åºä»ããªã¹ããããããšãæãåºããŠãã ããïŒãæ°ããèŠçŽ ãäœæããåäžã®CASããªããã£ãã§æ¿å ¥ããŸãïŒcompare-and-swapã
std::compare_exchange
ã§ããã
std::compare_exchange
ïŒã
åé€ãéåžžã«ç°¡åã§ãïŒ
åé€ãããèŠçŽ ãç·åœ¢çã«æ¢ããCASã«ãã£ãŠã¢ãããã¯ã«ãå è¡èŠçŽ ããåŸç¶èŠçŽ ãžã®ãã€ã³ã¿ãã¹ããŒããŸãã
åé¡ã¯ãããããã¹ãŠãåæã«äžŠè¡ããŠè¡ããããšãã«å§ãŸããŸããã¹ã¬ããAã¯ããŒ3ã®èŠçŽ ãåé€ããã¹ã¬ããBã¯ããŒ4ãæ¿å ¥ããŸãã
ã¹ã¬ããAãšBã¯åæã«æ€çŽ¢ããŸãã åæã«ãåé€ïŒAïŒããã³æ¿å ¥ïŒBïŒã§èŠã€ãã£ãäœçœ®ãããŒã«ã«å€æ°ã«èšæ¶ããŸãã 次ã«ãã¹ã¬ããAããªã¹ããã3ãå®å šã«åé€ããŸãããããšãã°ããã®æç¹ã§ã¹ã¬ããBã¯æŒãåºãããŠ
iprev
ããã³
inext
äœçœ®ãæ¢ã«ãããèŠçŽ ãæ¿å ¥ããã¢ãããã¯CASããªããã£ããå®è¡ããŸãã ãªã¹ããããã§ã«é€å€ãããŠããããŒ3ã®ã¢ã€ãã ã®åŸïŒ ïŒãã¶ãŒããã€ã³ã¿ãŒ/ RCUã¯ãèŠçŽ 3ããŸã ç©ççã«åé€ãããŠããªãããšãä¿èšŒããŸããã€ãŸãããã¬ããŒãžã¢ã¯ã»ã¹ããåãåããŸãããã3ã¯ã¹ã¬ããAã«ãã£ãŠãªã¹ãããæ¢ã«åé€ãããŠããŸãïŒã ãã¹ãŠããšã©ãŒãªãã§è¡ããããããããŒ4ã®èŠçŽ ã倱ãããããã«ã¡ã¢ãªãªãŒã¯ãçºçããŸããã
T.ããªã¹ã¯2001幎ã«ãã®åé¡ã®ãšã¬ã¬ã³ããªè§£æ±ºçãèŠã€ããŸããã 圌ã¯ãèŠçŽ ã®2段éã®åé€ãææ¡ããŸããïŒç¬¬1段é- è«çåé€ -èŠçŽ ããªã¹ãããé€å€ããã«åé€æžã¿ãšããŠããŒã¯ãã第2段é- ç©ççé€å€ -èŠçŽ ããªã¹ãããé€å€ããŸãïŒç¬¬3段é-ç©çåé€ -å®å šãªã¡ã¢ãªåé€ã¹ããŒã -ãã¶ãŒããã€ã³ã¿ãŒRCUãŸãã¯åæ§ïŒã è«çåé€ã®æå³ã¯ãCAS ãæ©èœããªãããã«ãåé€ããèŠçŽ ã«ããŒã¯ãä»ããããšã§ãã Harrisã¯ã
next
èŠçŽ ãã€ã³ã¿ãŒã®æäžäœãããã䜿çšããããšãææ¡ããŸããã å®éãææ°ã®ã¢ãŒããã¯ãã£ïŒããã»ããµãšOSã®äž¡æ¹ïŒã§ã¯ãããŒã¿ã¯4ïŒ32ãããã®å ŽåïŒãŸãã¯8ïŒ64ãããã®å ŽåïŒãã€ãã®å¢çã«æããããŠããããããã€ã³ã¿ãŒã®äžäœ2ãŸãã¯3ãããã¯åžžã«ãŒãã§ãããããããã©ã°ãšããŠäœ¿çšã§ããŸãã ãã®ããªãã¯ã«ã¯ã ãã€ã³ã¿ãŒãšããŒã¯ãããç¬èªã®ååãä»ããããŠãããããã¯ããªãŒããã°ã©ãã³ã°ã§åºã䜿çšãããŠããŸãã
ããŒã¯ä»ããã€ã³ã¿ãŒã䜿çšãããšã䞊åæ¿å ¥/åé€ã¯æ¬¡ã®ããã«ãªããŸãã
ã¹ã¬ããAã¯ãèŠçŽ 3ãè«ççã«ãªã¢ãŒããšããŠããŒã¯ããŸã
found->next
ãã€ã³ã¿ãŒã®äžäœãããã1ã«èšå®ããŸãã ããã§ã3ã®åŸã«4ãæ¿å ¥ããããšããã¹ã¬ããBã¯å€±æããŸã
3.next
ããŒã¯ãããŠããªããšæããããããCASã¯æ©èœããŸããã
ããŒã¯ããããã€ã³ã¿ãŒã¡ãœããã®äŸ¡æ Œã¯ãã¢ã€ãã ãåé€ããããšãã®è¿œå ã®CASåŒã³åºãã§ãã
äžèšã®ãã¹ãŠãäžèŠã§ãåé€ãããã¢ã€ãã ã®
next
ãã€ã³ã¿ãŒã
nullptr
èšå®ããã ãã§ã¯ããã«é«éã§ç°¡åã«æããŸã-æ¿å ¥ã®CASã¯æ©èœããŸããã ã¯ããç°¡åã§ããããããã¯2ã€ã®ç¬ç«ããæäœã§ãã1ã€ã¯äŸå€ã§ããã1ã€ã¯
next
ãŒãåã§ãã ãŸãã2ã€ã®æäœãããå Žåã誰ãããããã®éãããã³æ¢ããŠãæ¢ã«é€å€ãããŠããæäœã®åŸã«æ°ããèŠçŽ ãæ¿å ¥ã§ããŸãã ãããã£ãŠããšã©ãŒã®å¯èœæ§ãæžããã ãã§ãé€å€ããããšã¯ããŸããã ããã¯ããªãŒã®ãããã£é¢ïŒãã¹ãŠãå¯èœãªéãã¢ãããã¯ã«å®è¡ããå¿ èŠããããŸããããããã«ããŠããã³ã³ããã®å éšæ§é ã«éåããããšã¯ãããŸããã
æŽå²çé 足
ããã¯ããªãŒã®é åºä»ããªã¹ãçšã®Harrisã¢ã«ãŽãªãºã ã®èå³æ·±ãé²åã å
ã®ã¢ã«ãŽãªãºã ã¯ãååãšããŠããã¶ãŒããã€ã³ã¿ãŒã¹ããŒã ãé©çšã§ããªããšããäºå®ã«ãã£ãŠåºå¥ãããŸãã å®éãHarrisã®ã¢ã«ãŽãªãºã ã«ã¯ããªã³ã¯ãªã¹ãããŒãã®ãã§ãŒã³ã®ç©ççãªåé€ãå«ãŸããŸããããã¯ãååãšããŠç¡éã§ãã ç§ãã¡ãç¥ã£ãŠããããã«ããã¶ãŒããã€ã³ã¿ãŒã¹ããŒã ã§ã¯ããŸãåé€æžã¿ã¢ã€ãã ãå±éºç©ãšããŠå®£èšããŠä¿è·ã ããã®åŸã§äœããè¡ãå¿
èŠããããŸãã ãããããã¶ãŒããã€ã³ã¿ãŒã®æ°ã¯éãããŠãããããèŠçŽ ã®ç¡æ¬¡å
ãã§ãŒã³å
šäœãä¿è·ããããšã¯ã§ããŸããïŒ
ãã¶ãŒããã€ã³ã¿ãŒãéçºããéãMããã€ã±ã«ã¯ããªã¹ã®ãšã¬ã¬ã³ããªã¢ã«ãŽãªãºã ãžã®åœŒã®ã¹ããŒã ã®ãã®æ ¹æ¬çãªé©çšäžå¯èœæ§ãæããã«ãã2ãã§ãŒãºåé€ïŒããŒã¯ãã€ã³ã¿ãŒã®åä¿¡ïŒã䜿çšããŸãããèŠçŽ ãäžåºŠã«1ã€ãã€åé€ããããšã§ããã¶ãŒããã€ã³ã¿ãŒã®äœ¿çšãèš±å¯ããŸãã
æ€çŽ¢ãåéããåé¡ã解決ãããã®ã¢ã«ãŽãªãºã ã®å¥ã®å€æŽããããŸã ã ç§ãç¹°ãè¿ã匷調ããããã«ããã¹ãŠã®ããã¯ããªãŒã¢ã«ãŽãªãºã ã¯ããããŸããããŸã§ã¹ãããåãããç¡éã®ãµã€ã¯ã«ã§ãã äžèšã®èå³æ·±ãç¶æ³ã«ã€ããŠèª¬æããŸããããCASãæ©èœããªãã£ããšãã«äœãããå¿ èŠããããã«ã€ããŠã¯è§ŠããŸããã§ããã å®éããã¹ãŠãåçŽã§ããæ¿å ¥/åé€ã®CASãæ©èœããªãã£ãå ŽåãæåããïŒäœçœ®ã®æ€çŽ¢ããïŒæäœãå®è¡ããããå®è¡ã§ããªãããšãããããŸã§ãæ¿å ¥/åé€ãå床詊è¡ããå¿ èŠããããŸãã ïŒæ¿å ¥ã®å Žå-ããŒã¯æ¢ã«ãªã¹ãã«ãããããåé€ã®å Žå-ããŒã¯ãªã¹ãã«ãªãããïŒ ãªã¹ããé·ãå Žåããªã¹ãã®å é ããæäœãåéããã®ã¯è²»çšãããããŸãïŒãããŠãããã§èª¬æãããªã¹ãã«åºã¥ããŠãæ°çŸäžã®èŠçŽ ããµããŒãããããªãå¹ççãªé åºä»ããããã³ã³ãããŒã¢ã«ãŽãªãºã ãæ§ç¯ã§ããããšã¯åŸã§ããããŸãïŒããã®ãããæåãã2çªç®ã®æ€çŽ¢ãéå§ããå Žåãããã以åã®èŠçŽ ããïŒ ããããå»ã ãšå€åããããã¯ããªãŒã®äžçã«ããããåã®ããšããæŠå¿µã¯éåžžã«äžå®å®ã§ãã Fomichevã¯ã 圌ã®è«æã§ã以åã®èŠçŽ ãžã®åŸæ¹åç §ã®ããã¯ããªãŒãªã¹ãã®åèŠçŽ ã«è¿œå ããããšãææ¡ãããããã®ãã€ã³ã¿ãæäœããããããéåžžã«è€éãªææ°ã®ç¶æ ã«ä¿ã€æè¡ã«ã€ããŠèª¬æããŸãã
ããŠãããŒãã«ã¯-åèŠçŽ ã®ã¬ãã«ã§ã®ããã®çŽ°ããããã¯ã«åºã¥ããé åºä»ããªã¹ãã®ç¬èªã®ã¢ã«ãŽãªãºã ã é 延ãªã¹ãããããŸãã libcdsã«ãå®è£ ãããŠããŸãã ããã¯ããŒã¹ã®æ§è³ªã«ããããããããã®äžã«æ§ç¯ãããããã·ã¥ãããã¯ããã®èšäºã§èª¬æããããã¯ããªãŒã®åçç©ãããããã»ã©å£ã£ãŠããŸããã ãã¥ãŒããã¯ã¹ãšããŠãããã©ã«ãã§ã¯ã¹ãã³ããã¯ã䜿çšããŸãã
ãã¶ãŒããã€ã³ã¿ãŒãéçºããéãMããã€ã±ã«ã¯ããªã¹ã®ãšã¬ã¬ã³ããªã¢ã«ãŽãªãºã ãžã®åœŒã®ã¹ããŒã ã®ãã®æ ¹æ¬çãªé©çšäžå¯èœæ§ãæããã«ãã2ãã§ãŒãºåé€ïŒããŒã¯ãã€ã³ã¿ãŒã®åä¿¡ïŒã䜿çšããŸãããèŠçŽ ãäžåºŠã«1ã€ãã€åé€ããããšã§ããã¶ãŒããã€ã³ã¿ãŒã®äœ¿çšãèš±å¯ããŸãã
æ€çŽ¢ãåéããåé¡ã解決ãããã®ã¢ã«ãŽãªãºã ã®å¥ã®å€æŽããããŸã ã ç§ãç¹°ãè¿ã匷調ããããã«ããã¹ãŠã®ããã¯ããªãŒã¢ã«ãŽãªãºã ã¯ããããŸããããŸã§ã¹ãããåãããç¡éã®ãµã€ã¯ã«ã§ãã äžèšã®èå³æ·±ãç¶æ³ã«ã€ããŠèª¬æããŸããããCASãæ©èœããªãã£ããšãã«äœãããå¿ èŠããããã«ã€ããŠã¯è§ŠããŸããã§ããã å®éããã¹ãŠãåçŽã§ããæ¿å ¥/åé€ã®CASãæ©èœããªãã£ãå ŽåãæåããïŒäœçœ®ã®æ€çŽ¢ããïŒæäœãå®è¡ããããå®è¡ã§ããªãããšãããããŸã§ãæ¿å ¥/åé€ãå床詊è¡ããå¿ èŠããããŸãã ïŒæ¿å ¥ã®å Žå-ããŒã¯æ¢ã«ãªã¹ãã«ãããããåé€ã®å Žå-ããŒã¯ãªã¹ãã«ãªãããïŒ ãªã¹ããé·ãå Žåããªã¹ãã®å é ããæäœãåéããã®ã¯è²»çšãããããŸãïŒãããŠãããã§èª¬æãããªã¹ãã«åºã¥ããŠãæ°çŸäžã®èŠçŽ ããµããŒãããããªãå¹ççãªé åºä»ããããã³ã³ãããŒã¢ã«ãŽãªãºã ãæ§ç¯ã§ããããšã¯åŸã§ããããŸãïŒããã®ãããæåãã2çªç®ã®æ€çŽ¢ãéå§ããå Žåãããã以åã®èŠçŽ ããïŒ ããããå»ã ãšå€åããããã¯ããªãŒã®äžçã«ããããåã®ããšããæŠå¿µã¯éåžžã«äžå®å®ã§ãã Fomichevã¯ã 圌ã®è«æã§ã以åã®èŠçŽ ãžã®åŸæ¹åç §ã®ããã¯ããªãŒãªã¹ãã®åèŠçŽ ã«è¿œå ããããšãææ¡ãããããã®ãã€ã³ã¿ãæäœããããããéåžžã«è€éãªææ°ã®ç¶æ ã«ä¿ã€æè¡ã«ã€ããŠèª¬æããŸãã
ããŠãããŒãã«ã¯-åèŠçŽ ã®ã¬ãã«ã§ã®ããã®çŽ°ããããã¯ã«åºã¥ããé åºä»ããªã¹ãã®ç¬èªã®ã¢ã«ãŽãªãºã ã é 延ãªã¹ãããããŸãã libcdsã«ãå®è£ ãããŠããŸãã ããã¯ããŒã¹ã®æ§è³ªã«ããããããããã®äžã«æ§ç¯ãããããã·ã¥ãããã¯ããã®èšäºã§èª¬æããããã¯ããªãŒã®åçç©ãããããã»ã©å£ã£ãŠããŸããã ãã¥ãŒããã¯ã¹ãšããŠãããã©ã«ãã§ã¯ã¹ãã³ããã¯ã䜿çšããŸãã
ãã®ãããããã¯ããªãŒããã·ã¥ããããå®è£ ã§ããé åºä»ããªã¹ãã®ããã¯ããªãŒã¢ã«ãŽãªãºã ãåæããŸããã ãã®ã¢ã«ãŽãªãºã ã®æ¬ ç¹ã¯ãåããã·ã¥ãæäŸãããªãããšã§ããã€ãŸãããã®ãããªã³ã³ããå ã®SèŠçŽ ã®æšå®æ°ãšæé©ãªè² è·ä¿æ°ãäºåã«ç¥ãå¿ èŠããããŸãã 次ã«ãããã·ã¥ããŒãã«ã®ãµã€ãºN
T[N]
ã¯ã
S / load factor
çãããªã
S / load factor
ã ããã«ããããããããããã®å¶éã«ãããããããããããããã®ãããã§ããã®ãããªã¢ã«ãŽãªãºã ã¯åããã·ã¥ã®ãªãŒããŒãããããªããããæãé«éã§æãã¹ã±ãŒã©ãã«ãªã¢ã«ãŽãªãºã ã®1ã€ã§ãã
ç§ã®å®éšã®çµæã«ãããšãé©åãªè² è·ä¿æ°ã¯2ã4ã§ããã€ãŸããè¡çªã®ããã¯ããªãŒãªã¹ãã«ã¯ããããå¹³å2ã4åã®èŠçŽ ãå«ãŸããŠããŸãã è² è·ä¿æ°= 1ïŒè¡çªãªã¹ãã¯å¹³åã§1ã€ã®èŠçŽ ã§æ§æãããŸãïŒã®å Žåãçµæã¯ãããã«è¯ããªããŸãããå®éã«çž®éããè¡çªãªã¹ãã®ã¡ã¢ãªãªãŒããŒããããå¢ããŸãã
次ã®èšäºã§ã¯ãå ã åããã·ã¥ããµããŒãããããã§èª¬æããããã¯ããªãŒã®é åºä»ããªã¹ãã«åºã¥ãã¢ã«ãŽãªãºã ãæ€èšããŸãã
ããã¯ããªãŒã®ããŒã¿æ§é
éå§ãã
åºæ¬ïŒ
äžïŒ
å€ããïŒ
åºæ¬ïŒ
- ååæ§ããã³ååããªããã£ã
- èšæ¶ã®å£ã¯ã©ãããæ¥ãã®ã§ããïŒ
- ã¡ã¢ãªã¢ãã«
äžïŒ
- ã¡ã¢ãªç®¡çã¹ããŒã
- RCU
- ã¹ã¿ãã¯ã®é²å
- å¥ã®è«æ
- ãã¥ãŒåæ
- 䞊è¡ãããïŒãŠã©ãŒã ã¢ãã
- 䞊è¡ãããïŒåããã·ã¥ãåæ§ç¯ãªã
- 䞊è¡ãããïŒãªã¹ããã¹ããã
- äžèŽãããïŒæš
- ã€ãã¬ãŒã¿ïŒãã«ãã¬ãã«é å
- å埩å¯èœãªãªã¹ã
å€ããïŒ