
ãã®èšäºã§ã¯ãlibcdsããŒã¿æ§é ã®ããã¯ããªãŒã©ã€ãã©ãªãŒã®äœ¿çšæ¹æ³ã®æŠèŠã説æããŸãã ããã§ã®å®è£ ã«ã€ããŠã¯èª¬æããŸããã å€åŽããèŠãã ãã§ãå³æžé€šå©çšè ã®åŽããèŠããã®ã§ãã
libcdsã©ã€ãã©ãªã«ã¯ãå€ãã®æåãªããŒã¿æ§é ã«é¢ããç¬èªã®èŠç¹ããããŸãã ããã¯ãã¿ãŒã²ããé åã«ãã£ãŠéšåçã«èª¬æãããŸã-ããã¯ããªãŒã®ããŒã¿æ§é ã¯ãæäŸãããã¡ãœããã®ã»ããã®èŠ³ç¹ããã¯æå°éã§ã-äžéšã¯ãæšæºSTLã©ã€ãã©ãªã®å¶éãšãœãªã¥ãŒã·ã§ã³ãè¶ ããããšãã欲æ±ã«ãã£ãŠã ãã®çµæã¯ãlibcdsãŠãŒã¶ãŒã決å®ããå¿ èŠããããŸãã
誰ãæ°ã«ãã-ç«ãžãããã
Libcdsã¯ãããã¯ããªãŒã®ããŒã¿æ§é ãšãããã¯ããªãŒã®æ§é ã®ããã®å®å šãªã¡ã¢ãªåçïŒSMRïŒã¡ãœããã®C ++ã©ã€ãã©ãªã§ãã ã»ãšãã©ããããŒã®ã¿ã§ãããã¹ãŠã®ããŒã¿æ§é ã¯ããããŒ.hãã¡ã€ã«ã§å®çŸ©ãããã³ã¢SMRã¢ã«ãŽãªãºã ã®å®è£ ã®ã¿ãå°ããªåçã©ã€ãã©ãªã«ç§»åãããŸãã
SMRã®æŠèŠ
ãããããããã¯ããªãŒããŒã¿æ§é ãéçºããéã®æãèããã€ã³ãã¯ãã³ã³ããèŠçŽ ãå®å šã«ç©ççã«åé€ã§ããæç¹ã決å®ããããšã§ãã èŠçŽ ã®åé€ã¯åžžã«2段éã®æäœã§ããæåã«ãã³ã³ããããèŠçŽ ãé€å€ãã次ã«èŠçŽ ã«å²ãåœãŠãããã¡ã¢ãªãåé€ïŒå²ãåœãŠè§£é€ïŒããŸãã ããã¯ããªãŒã¢ãããŒãã§ã¯ã2çªç®ã®ãã§ãŒãºã§ããç©çåé€ã§ã¯ãåé€ãããã¢ã€ãã ãžã®ãªã³ã¯ïŒã°ããŒãã«ãŸãã¯ããŒã«ã«ïŒã誰ãããªãïŒäžŠåã¹ã¬ããã¯ãªãïŒãšããå®å šãªç¢ºå®æ§ãå¿ èŠã§ãã
å®å šã«åé€ããã«ã¯ãSMRã¢ã«ãŽãªãºã ã責任ãè² ããŸããããã¯ãç¹æ®ãªã¬ããŒãžã³ã¬ã¯ã¿ãŒïŒGCïŒãšèŠãªãããšãã§ããŸãã ãã®èšäºã§ã¯ãç¹å®ã®SMRã¢ã«ãŽãªãºã ã®å®è£ ã®å éšè©³çŽ°ã«ã€ããŠã¯èª¬æããŸãããlibcdsã®äœ¿çšãéå§ããã®ã«ååãªäžè¬çãªèª¬æã®ã¿ã瀺ããŸãã ä»åŸã®èšäºã§ãã¹ãŠã®ã¢ã«ãŽãªãºã ã«ã€ããŠè©³ãã説æããããšæããŸãã
次ã®SMRã¢ã«ãŽãªãºã ãlibcdsã«å®è£ ãããŠããŸãã
- ãã¶ãŒããã€ã³ã¿ãŒã¯ãããããæåã§æãæåãªSMRã¢ã«ãŽãªãºã ã§ãã 2002幎ã«ãã€ã±ã«ïŒããã¯å§ïŒã«ãã£ãŠçºæãããŸãã[Mic02ãMic03ãMic04]ã æ¯èŒçåçŽã§é床ãéãããšã§åºå¥ãããã³ã³ããèŠçŽ ãžã®ããŒã«ã«ãªã³ã¯ã®ãä¿è·ããç®çãšããŠããŸãã æ¬ ç¹-åæã«å®è¡ãããã¹ã¬ããã®æ倧æ°ã瀺ãå¿
èŠããããŸãã ããããŒãã¡ã€ã«
<cds/gc/hp.h>
ãã¯ã©ã¹cds::gc::HP
- Pass-the-Buck-æŠå¿µçã«ã¯ãã¶ãŒããã€ã³ã¿ãŒã«äŒŒãŠããŸãããã¹ã¬ããã®æ°ã«äŸåããŸããã 2002幎ã«HerlihyãVãLuchangcoãããã³M. Moirã«ãã£ãŠææ¡ãããŸãã[Her02ãHer05]ã ã¹ã¬ããã®æ°ãç¬ç«ããŠããããããã¶ãŒããã€ã³ã¿ãŒãããå°ãéãã§ãã ããããŒãã¡ã€ã«
<cds/gc/ptb.h>
ãã¯ã©ã¹cds::gc::PTB
- åç
§ã«ãŠã³ãä»ããã¶ãŒããã€ã³ã¿ãŒã¯ãHÃ¥kanSundell-Gidenstam et alã[Gid05ãGid06]ãçããã¹ãŠã§ãŒãã³ã®åŠæ ¡ã®ä»£è¡šè
ã«ãã£ãŠææ¡ããããã¶ãŒããã€ã³ã¿ãŒã¢ã«ãŽãªãºã ã®ããªãšãŒã·ã§ã³ã§ãã ãã¶ãŒããã€ã³ã¿ãŒãšåæ§ã«ãã¹ã¬ããã®æ°ã«äŸåããŸãã ç¹åŸŽçãªæ©èœã¯ãã³ã³ããèŠçŽ ãžã®ã°ããŒãã«åç
§ãä¿è·ã§ããããšã§ããã€ãŸããã€ãã¬ãŒã¿ãå®è£
ã§ããŸãã ããã©ãŒãã³ã¹ã®äœäžãšãŸããªäžå
·åã®ããã䜿çšã¯æšå¥šãããŸããïŒæåŸãŸã§ãããã°ã§ããŸããïŒã ããããŒãã¡ã€ã«
<cds/gc/hrc.h>
ãã¯ã©ã¹cds::gc::HRC
- RCUïŒRead-Copy UpdateïŒ -äžèšãšã¯ç°ãªãããã®ã¢ã«ãŽãªãºã ã¯åæã¢ã«ãŽãªãºã ãæããŸããã€ãŸããèŠçŽ ã®åé€æã«ã¹ã¬ããã®å®è¡ãäžæåæ¢ããŸãããä»ã®æäœã®äžŠåå®è¡ïŒè²Œãä»ããæ€çŽ¢ïŒãèš±å¯ããŸãããããã£ãŠããŸãã«åé€ãããããŒã¿æ§é ã«é©ããŠããŸããã¿ã€ãããããã»ããã Paul McKenneyã«ãã£ãŠææ¡ãããLinuxã«ãŒãã«ã§ç©æ¥µçã«äœ¿çšãããŠããŸãã ãªãªãžãã«ã®RCUã¯OSã®ã«ãŒãã«ã«ã®ã¿å®è£
ã§ããŸããã2009幎ã«Desnoyersã¯ã¢ããªã±ãŒã·ã§ã³çšã®RCUã®ããŒãžã§ã³ïŒãŠãŒã¶ãŒã¹ããŒã¹RCUãURCUïŒ[Des09ãDes11]ãææ¡ããŸãããããã¯libcdsã«å®è£
ãããŠããŸãã ãã®ã©ã€ãã©ãªã¯ãURCUã®5ã€ã®å®è£
ãæäŸããæãå¹æçãªã®ã¯ãããã¡ãªã³ã°ãããURCUã§ãã ããããŒãã¡ã€ã«
<cds/urcu/general_buffered.h>
ãã¯ã©ã¹cds::urcu::gc< cds::urcu::general_buffered<> >
ã libcdsã§ã¯ãURCUã¯ããããšèšå®ã«ã®ã¿é©çšãããŸã

ãã¹ãŠã®SMRã¢ã«ãŽãªãºã ã«ã¯ãGCãè¡šãåäžã®ãªããžã§ã¯ããå¿ èŠã§ããã€ãŸããGCã¯ã·ã³ã°ã«ãã³ã§ãã åçã©ã€ãã©ãªã§ããlibcdsã³ã¢ã«ã¯ãåºæ¬çãªSMRã¢ã«ãŽãªãºã ã®å®è£ ã®ã¿ãå«ãŸããŠããŸãã
ååãšããŠãã¢ããªã±ãŒã·ã§ã³ã¯1ã€ã®SMRã¢ã«ãŽãªãºã ã®ã¿ã䜿çšããå¿ èŠããããŸãïŒlibcdsã§ã¯è€æ°ã®ç°ãªãGCã¢ã«ãŽãªãºã ã䜿çšã§ããŸãããããããã¹ãŠã®ãã¹ãã®æ§ç¯æ¹æ³ã§ãããåãGCã®2ã€ã®ãªããžã§ã¯ãã¯äœ¿çšã§ããŸããïŒã ãããã£ãŠãæåã«è¡ãããšã¯ãSMRã¢ã«ãŽãªãºã ãéžæããããšã§ãã libcdsã®ããŒã¿æ§é ã®ã»ãšãã©ã®ã¯ã©ã¹ã«ã¯ãæåã®ãã³ãã¬ãŒãåŒæ°ã§ããã¡ã¢ãªç®¡çã¢ã«ãŽãªãºã ãšããŠGCããããŸãã ããã«ãåGCã¯ã©ã¹ã«ã¯ç¬èªã®ã³ã³ããã¯ã©ã¹ã®ãã³ãã¬ãŒãã®ç¹æ®åããããããç°ãªãGCã®å ŽåãååãšããŠãã³ã³ããã¯ã©ã¹ã®ç°ãªãããããŒãã¡ã€ã«ãå«ããïŒå«ããïŒå¿ èŠããããŸãã
SMRã¢ã«ãŽãªãºã ã䜿çšããããã«ãGCã®å éšæ§é ãç¥ãå¿ èŠã¯ãããŸãããGCãšå¯Ÿè©±ãããã¹ãŠã®ã¡ã«ããºã ã¯ãã³ã³ããã¯ã©ã¹å ã«é ãããŠããŸãã ãã ããããã°ã©ã ã®éå§æãããã³GCäŸåã³ã³ããã䜿çšããåã¹ã¬ããã®éå§æã«ãGCã·ã³ã°ã«ãã³ãªããžã§ã¯ããåæåããå¿ èŠããããŸãã
GCããªãŒå®¹åš
libcdsã«ã¯ãGCã䜿çšããªãããã¯ããªãŒã®ããŒã¿æ§é ãããã€ããããŸãã
- æŽç·ŽãããïŒãã现ããïŒåæã¢ã«ãŽãªãºã ã䜿çšããããã¯ããŒã¹ã®ã³ã³ãã
- æ倧ãµã€ãºã®ã³ã³ããã«å¶éãããŠããŸã
- setããã³mapãèŠçŽ ã®åé€æäœããµããŒãããŸããïŒè¿œå ã®ã¿ïŒã ååãšããŠãåã»ãã/ããããã³ãã¬ãŒãã¯ã©ã¹ã«ã¯ããGCã
cds::gc::nogc
ã«å¯Ÿããç¬èªã®ç¹æ®åããããŸããcds::gc::nogc
ã¯ãå®éã«ã¯ã³ã³ãããåé€ããµããŒãããŠããªããšããäºå®ã®å°ã§ã
libcdã®åæå
ã©ã€ãã©ãªã®åæåã¯ãGCãªããžã§ã¯ãã宣èšããããšã§ãã ãã®ãªããžã§ã¯ãã¯ãããã°ã©ã å ã§å¯äžã®ãã®ã§ãªããã°ãªããŸããã GCãªããžã§ã¯ãã¯ãSMRã¢ã«ãŽãªãºã ã®å éšå®è£ ã«å¯Ÿããåãªããªããžã§ã¯ãæåã®ã¢ããªã³ã§ãã ååãšããŠãããã°ã©ã ã¯GCãªããžã§ã¯ãã®ã¡ãœããã«ã¢ã¯ã»ã¹ããå¿ èŠã¯ãããŸãããGCãšã®ãã¹ãŠã®å¯Ÿè©±ã¯ããã¯ããªãŒããŒã¿æ§é å ã«é ãããŠãããããGCãªããžã§ã¯ãã¯ããŒã«ã«ã«ãªããŸãã
libcdsã§ã¯ããã¹ãŠã®ç°ãªãã¿ã€ãã®GC-
cds::gc::HP
ã
cds::gc::PTB
ã
cds::urcu::gc< cds::urcu::general_buffered<> >
ãªã©-åäžã«åæåãããŸãããã³ã³ã¹ãã©ã¯ã¿ã¯ç¹å®ã®GCã®ãã©ã¡ãŒã¿ãŒãæå®ããããŸããŸãªåŒæ°ãåãããšãã§ããŸãã GCã³ã³ã¹ãã©ã¯ã¿ãŒã®ãã¹ãŠã®åŒæ°ã«ã¯ããã©ã«ãå€ããããŸãã ãã®å ¥éèšäºã§ã¯ãããã©ã«ãå€ã«äŸåããŠãåŒæ°ãªãã§ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºããŸãã
ãã¶ãŒããã€ã³ã¿ãŒã¡ã¢ãªç®¡çã¢ã«ãŽãªãºã ã®åæåã³ãŒãã¯æ¬¡ã®ããã«ãªããŸãã
#include <cds/init.h> //cds::Initialize cds::Terminate #include <cds/gc/hp.h> //cds::gc::HP (Hazard Pointer) int main(int argc, char** argv) { // libcds cds::Initialize() ; { // Hazard Pointer cds::gc::HP hpGC ; // main thread lock-free // main thread // libcds cds::threading::Manager::attachThread() ; // , libcds // ... } // libcds cds::Terminate() ; }
cds::Initialize()
é¢æ°ã¯ãããã€ãã®ã°ããŒãã«ãªå éšlibcdsããŒã¿ãåæåããã·ã¹ãã ããããžã決å®ããŸãã ããã«ç¶ããŠãGCãªããžã§ã¯ããäœæãããŸãããã®äŸã§ã¯ããã¶ãŒããã€ã³ã¿ãŒãã¯ã©ã¹
cds::gc::HP
ããªããžã§ã¯ãã¯ããã©ã«ãã®åŒæ°ã§äœæãããŸãã
main
ã®æåŸã«ã
cds::Terminate
library terminatoré¢æ°ãåŒã³åºããŸããããã«ãããå éšæ§é ã解æŸãããŸãã
cds :: InitializeïŒïŒããã³cds :: TerminateïŒïŒãžã®åŒã³åºããåãé€ãããšã¯å¯èœã§ããïŒ
ããã³
ïŒããšãã°ã
dllãã¡ã€ã«ã§ããããå®çŸ©ããããGCCã®constructor / destructorå±æ§ã§éçå éšé¢æ°ãšããŠå®£èšãã
ã®åŒã³åºããåãé€ããšããããã®é¢æ°ã¯ååã€ã³ã©ã€ã³ã«ãªããã倱æããŸãäžè¬çã«ããããã¯ã³ã³ãã€ã©ã®ã³ãã³ãã©ã€ã³ã§æå®ã§ãããã¯ãã«äŸåããŠããŸãã
cds::Initialize()
ããã³
cds::Terminate
ïŒããšãã°ã
DllMain
dllãã¡ã€ã«ã§ããããå®çŸ©ããããGCCã®constructor / destructorå±æ§ã§éçå éšé¢æ°ãšããŠå®£èšãã
cds::Initialize()
ã®åŒã³åºããåãé€ããšããããã®é¢æ°ã¯ååã€ã³ã©ã€ã³ã«ãªããã倱æããŸãäžè¬çã«ããããã¯ã³ã³ãã€ã©ã®ã³ãã³ãã©ã€ã³ã§æå®ã§ãããã¯ãã«äŸåããŠããŸãã
ã¹ã¬ããã®åæå
å€ãã®SMRã¢ã«ãŽãªãºã ãšããã¯ããªãŒããŒã¿æ§é ã«ã¯ãã¹ã¬ããããã®ãµããŒããå¿ èŠã§ãã ããšãã°ãäžéšã®ããŒã¿ã¯ã¹ã¬ããã«å¯ŸããŠããŒã«ã«ã§ããããïŒã¹ã¬ããããšã®ããŒã¿ïŒãã¹ã¬ããããŒã«ã«ã¹ãã¬ãŒãžïŒTLSïŒã«ããå¿ èŠããããŸãã ããã確å®ã«ããããã«ãäžéšã®å®è£ ã§ã¯ãã¹ã¬ããã®ãããŒå¶åŸ¡ããªã·ãŒãŸãã¯ã¯ã©ã¹éå±€ãæ瀺ããŸãã ãã¡ãããããã¯ã©ã€ãã©ãªéçºè ã«ãšã£ãŠã¯äŸ¿å©ã§ããããŠãŒã¶ãŒã«ãšã£ãŠã¯å®å šã«äžäŸ¿ã§ãã ãããã£ãŠãlibcdãèšèšãããšããç§ã¯å¥ã®æ¹æ³ã§è¡ã£ããã©ã€ãã©ãªã¯ãéžæããã¹ããªãŒã ã®ã¢ãã«ïŒãŸãã¯ã¯ã©ã¹éå±€ïŒã«äŸåããŸããããã¹ããªãŒã ã«æ瀺çã«æ¥ç¶ïŒã¢ã¿ããïŒããå¿ èŠããããŸãã
libcdsã®ã³ã³ããã§åäœããåã¹ã¬ããã¯ã次ã®ããã«åæåããå¿ èŠããããŸãã
// cds::threading::Manager #include <cds/threading/model.h> int myThreadEntryPoint(void *) { // libcds cds::threading::Manager::attachThread() ; // // lock-free libcds ... // libcds cds::threading::Manager::detachThread() ; return 0; }
cds::threading::Manager
ã¯ã©ã¹ã¯ãå éšãããŒå¶åŸ¡ã€ã³ãã©ã¹ãã©ã¯ãã£ã®ã¢ããã¿ãŒã¯ã©ã¹ã§ãã libcdsã€ã³ãã©ã¹ãã©ã¯ãã£ãžã®ã¹ããªãŒã ã®æ¥ç¶/åæã«ã®ã¿å¿ èŠã«ãªãå ŽåããããŸãã
äžèšã®ã¹ã¬ããåæåã³ãŒãã¯ãäŸå€ã«é¢ããŠå®å šã§ã¯ãããŸããã ããæ£ããã¢ãããŒãã¯ãã³ã³ã¹ãã©ã¯ã¿ãŒãã¹ããªãŒã ãlibcdsã€ã³ãã©ã¹ãã©ã¯ãã£ã«æ¥ç¶ãããã¹ãã©ã¯ã¿ããããåæãããªããžã§ã¯ãã䜿çšããããšã§ãã ãã®ãããåGCã¯ã©ã¹ã«ã¯å éš
thread_gc
ã¯ã©ã¹ããããŸãã ããã«ãããã¹ããªãŒã ã®åæåã¯æ¬¡ã®ããã«ãªããŸãã
#include <cds/gc/hp.h> int myThreadEntryPoint(void *) { // libcds cds::gc::HP::thread_gc threadGC ; // // lock-free libcds ... return 0; }
ã¹ããªãŒã ãç§ãã¡ã«ãã£ãŠäœæãããŠããªãå Žåã¯ã©ããªããŸããïŒ
ç§ãã¡ãäœæãããã®ã§ã¯ãªãlibcdsã«ã¹ããªãŒã ãæ¥ç¶ããå¿
èŠãããå Žåãããããã®ã¹ããªãŒã ã®åæåã«åœ±é¿ãäžããããšã¯ã§ããŸããã ããšãã°ãã¢ããªã±ãŒã·ã§ã³ã¯WebãµãŒããŒãã©ã°ã€ã³ã§ãã WebãµãŒããŒã¯ã¹ã¬ããããŒã«ãäœæãããããã®ã¹ã¬ããã®ã³ã³ããã¹ãã§ãã©ã°ã€ã³ã«å®è£
ããããã³ãã©ãŒãåŒã³åºããŸãã ãã®å Žåã
åã®ãªããžã§ã¯ãã宣èšããŠãGCãªããžã§ã¯ããäœæããããã¹ã¬ãããåæåããããšã¯ã§ããŸããã ã©ããã
libcdså éšåæåã¡ã«ããºã ã䜿çšããå¿ èŠããããŸããã©ã€ãã©ãªåæåã¯ã©ã¹ãäœæãããã®ã¯ã©ã¹ã®éçãªããžã§ã¯ãã宣èšããŸãã
åæå
代ããã«ã察å¿ããåŒã³åºãã
ïŒWindowsã®å ŽåïŒãŸãã¯ã³ã³ã¹ãã©ã¯ã¿ãŒ/ãã¹ãã©ã¯ã¿é¢æ°ïŒGCCã®å Žåã¯
ã«é 眮ã§ããŸãã
ã¹ã¬ããã®åæåã¯ã
åŒã³åºããŠãæ°žä¹ ã«ãæ¥ç¶ããããšã§æ§æãããŸãã
ã¹ããªãŒã ã®ã·ã£ããããŠã³ã¯çºçããŸããã
GC::thread_gc
åã®ãªããžã§ã¯ãã宣èšããŠãGCãªããžã§ã¯ããäœæããããã¹ã¬ãããåæåããããšã¯ã§ããŸããã ã©ããã
libcdså éšåæåã¡ã«ããºã ã䜿çšããå¿ èŠããããŸããã©ã€ãã©ãªåæåã¯ã©ã¹ãäœæãããã®ã¯ã©ã¹ã®éçãªããžã§ã¯ãã宣èšããŸãã
#include <cds/gc/hp.h> class LibcdsInit { public: LibcdsInit() { // libcds cds::Initialize(); // Hazard Pointer singleton cds::gc::hzp::GarbageCollector::Construct() ; } ~LibcdsInit() { // Hazard Pointer singleton // true â // Hazard Pointer cds::gc::hzp::GarbageCollector::Destruct(true) ; // libcds cds::Terminate(); }; }; // static LibcdsInit libcdsInitializator ;
LibcdsInit
åæå
LibcdsInit
代ããã«ã察å¿ããåŒã³åºãã
DllMain
ïŒWindowsã®å ŽåïŒãŸãã¯ã³ã³ã¹ãã©ã¯ã¿ãŒ/ãã¹ãã©ã¯ã¿é¢æ°ïŒGCCã®å Žåã¯
__attribute__((constructor))
ã«é 眮ã§ããŸãã
ã¹ã¬ããã®åæåã¯ã
cds::threading::Manager::attachThread()
åŒã³åºããŠãæ°žä¹ ã«ãæ¥ç¶ããããšã§æ§æãããŸãã
// cds::threading::Manager #include <cds/threading/model.h> void callback() { Cds::threading::Manager::attachThread(); // lock-free // libcds }
ã¹ããªãŒã ã®ã·ã£ããããŠã³ã¯çºçããŸããã

ã³ã³ãã
ã©ã€ãã©ãªãåæåããåŸãããã¯ããªãŒã®ããŒã¿æ§é ã䜿çšã§ããŸãã libcdsã§ã¯ãã³ã³ããã¯2ã€ã®å€§ããªã¯ã©ã¹ã«åé¡ãããŸã-éåžžã®äŸµå ¥ãš
éåžžã¯STLã¹ã¿ã€ã«ã®ã³ã³ããã§ãããããŒã¿ã®ã³ããŒãä¿åããŸãã ãã®ãããªã³ã³ããã¯ãã¹ãŠã
cds::container
åå空éã§å®£èšãããŸãã
äŸµå ¥åã³ã³ããã«ã¯ãã³ããŒã§ã¯ãªãå®éã®ããŒã¿ãæ ŒçŽãããŸãã ã¢ã€ãã¢ã¯ã boost :: intrusiveããåãããŠããŸãã äŸµå ¥åã³ã³ãããŒã®å©ç¹ã¯ãããŒã¿ã®ã³ããŒãäœæããããã«ã¢ãã±ãŒã¿ãŒãåŒã³åºãå¿ èŠããªãããšã§ãã ã¢ãã±ãŒã¿ãŒèªäœã«åæããªããã£ããå«ãŸããŠãããããæšæºã®ã¢ãã±ãŒã¿ãŒã䜿çšãããšããã¯ããªãŒã®æŠå¿µãç¡å¹ã«ãªããšèããããŸãã äžè¬çãªå Žåãããã¯æ£ããã§ãããææ°ã®é«åºŠãªã¢ãã±ãŒã¿ãŒã¯ãããšãã°ãåã¹ã¬ããã®ã¡ã¢ãªããŒã«ã®ååšã«ããå éšåæãæé€ããããšã«ãããã¡ã¢ãªå²ãåœãŠãæé©åã§ããŸãã
ãã®èšäºã§ã¯ãäŸµå ¥åã³ã³ãããŒã«ã€ããŠè©³ããã¯èª¬æããŸãã-ã³ã³ãããŒããèŠçŽ ãé€å€ããããšãã«ã¡ã¢ãªãŒã解æŸããã«ã¯ç¹å¥ãªææ³ãå¿ èŠã§ããããã¯å¥ã®è°è«ã®ãããã¯ã§ãã ããã§ãéåžžã®ã³ã³ããã®ã»ãšãã©ã®ã¯ã©ã¹ã¯äŸµå ¥åã«åºã¥ããŠããããšã«æ³šæããŠãã ãããã€ãŸããååãšããŠããã¹ãŠã®èå³æ·±ãããã¯ããªãŒã³ãŒãã¯äŸµå ¥åã³ã³ããã®ã¯ã©ã¹ã«ãããŸãã äŸµå ¥ã³ã³ããã¯ã
cds::intrusive
宣èšãã
cds::intrusive
ã
libcdsã®ãã¹ãŠã®ããŒã¿æ§é ã¯ãçµ±äžããããã³ãã¬ãŒãã€ã³ã¿ãŒãã§ã€ã¹ãæã€ãã³ãã¬ãŒãã¯ã©ã¹ã§ãã 次ã®2çš®é¡ã®ãã³ãã¬ãŒãã€ã³ã¿ãŒãã§ã€ã¹ãåºå¥ã§ããŸãã
- å¯å€é·ãã³ãã¬ãŒãã«åºã¥ã
- ç¹æ§ã«åºã¥ããŠ
å¯å€é·ãã³ãã¬ãŒãããŒã¹ã®åºåã¯ãã¹ã¿ãã¯ãšãã¥ãŒã®åçŽãªã³ã³ããã«äœ¿çšãããŸãã äžè¬çãªãã¿ãŒã³ã¯æ¬¡ã®ãšããã§ãã
template <typename GC, typename T, typename⊠Options> class queue { ⊠};
å¯å€é·ãã³ãã¬ãŒãããµããŒãããªãã³ã³ãã€ã©ãŒã«ã¯ããšãã¥ã¬ãŒã·ã§ã³ã䜿çšãããŸãã
ã³ã³ããã¯ã©ã¹å ã§ã¯ã
Options
ã¯
Traits
æ§é ã«ããã±ãŒãžåãããŠããŸãã
Variadicãã³ãã¬ãŒãã¢ãããŒãã¯è€éãªç¶æ¿ã«ã¯ããŸã䟿å©ã§ã¯ãªãã£ããããç¹æ§å®£èšã¯
set
ã
map
ãªã©ã®ããè€éãªã³ã³ããã®ã¯ã©ã¹ã«äœ¿çšãããŸãã
template <typename GC, typename T, typename Traits> class set { ⊠};
ãã®ãããªã¯ã©ã¹ããšã«ãå¯å€ãã³ãã¬ãŒããç¹æ§ã«å€æãã
make_traits
ã¡ã¿é¢æ°ããããŸãã
template <typename⊠Options> struct make_traits { typedef typename pack<OptionsâŠ>::type type ; };
make_traits
ã䜿çšãããšãã³ã³ãããªããžã§ã¯ãã®å®£èšã¯æ¬¡ã®åœ¢åŒã«ãªããŸãã
struct Foo { ⊠}; cds::container::SkipListSet< cds::gc::HP, Foo, typename cds::container::skip_list::make_traits< Opt1, Opt2, Opt3 >::type > theSkipListSet ;
ãã¡ããããã®ãããªã¢ããŠã³ã¹ã¯ã¯ãŒã«ã«èŠããŸããããããã°æã«åé¡ãçºçããå¯èœæ§ããããŸã-ã¯ã©ã¹åã«ã¯æ°åè¡ãããå ŽåããããŸãã ãããã°ã®ããã®ç¹æ§ã¯ããã³ã³ãã¯ãã§ãïŒ
struct Foo { ⊠}; struct skipListSetTraits: public cds::container::skip_list::make_traits< Opt1, Opt2, Opt3 >::type {}; cds::container::SkipListSet< cds::gc::HP, Foo, skipListSetTraits > theSkipListSet ;
ããŒã¿æ§é ã¯ã©ã¹ã®ãã³ãã¬ãŒãåŒæ°ã¯æ¬¡ã®ãšããã§ãã
-
GC
-SMRã¢ã«ãŽãªãºã ãäœ¿çš -
T
ã³ã³ããã«ä¿åãããŠããããŒã¿ã®ã¿ã€ã -
OptionsâŠ
ãŸãã¯Traits
-ã³ã³ãããŒã®ãªãã·ã§ã³ïŒããªã·ãŒãæŠç¥ïŒ
ãªãã·ã§ã³ã¯åå¥ã«èª¬æããå¿ èŠããããŸãã

ãªãã·ã§ã³
åã³ã³ããã¯ã©ã¹ã¯ãããŒã¿ã¿ã€ããšSMRã¢ã«ãŽãªãºã ã«å ããŠããã®åäœãŸãã¯ãã®åäœãæå®ããããŸããŸãªè¿œå èšå®ãæã€ããšãã§ããŸãã ããšãã°ãé åºä»ããããã³ã³ããïŒmapãsetïŒã®å ŽåãèŠçŽ
std::less<T>
ãæ¯èŒããããã®ãã€ããªè¿°èªãæå®ããå¿ èŠããããŸãã ãŸãã¯ã䞊è¡äœæ¥ã®æ€åºæã«ãã®ã¢ã¯ã·ã§ã³ãŸãã¯ãã®ã¢ã¯ã·ã§ã³ã®æŠç¥ãèšå®ããïŒããã¯ãªãæŠç¥ïŒã ãŸãã¯ãã³ã³ããèŠçŽ ã®äœæã«äœ¿çšãããã¢ãã±ãŒã¿ãã€ã³ã¹ããŒã«ããŸãã
åã³ã³ããã¯ã©ã¹ã«ã¯ãã«ãŒã«ããªãã·ã§ã³èšå®ãªã©ãããã€ãïŒæ倧ã§12åïŒãããããããããªãã·ã§ã³ãšåŒã³ãŸãã åèšå®ãã¯ã©ã¹ãã³ãã¬ãŒãã®ãã³ãã¬ãŒãåŒæ°ã§ããå Žåã«STLã§äœ¿çšãããã¢ãããŒãã¯ãããŸã奜ãã§ã¯ãããŸãããããã©ã«ãå€ãæã€ãã®ãããªäœçœ®äŸåã®åŒæ°ã¯ãã¯ã©ã¹ã®äœ¿çšãè€éã«ããŸãã ã¯ã©ã¹ã«ããã©ã«ãå€ãæã€10åã®ãã³ãã¬ãŒãåŒæ°ãããå Žåã8çªç®ã®åŒæ°ãå€æŽããã«ã¯ã8çªç®ã®åã«ãã7ã€ã®åŒæ°ãã¹ãŠã®ããã©ã«ãå€ãæå®ããå¿ èŠããããŸãã ããã¯éåžžã«äžäŸ¿ã§ãã ãããã£ãŠãlibcdã§ã¯ãäœçœ®ã«äŸåããªãã¢ãããŒãã䜿çšããŸãã
ãã®ã¢ãããŒãã§ã¯ãåãªãã·ã§ã³ã«ç¬èªã®ã¿ã€ãããããŸãã ããšãã°ããã¢ãã±ãŒã¿ãŒããªãã·ã§ã³ã«ã¯æ¬¡ã®å®£èšããããŸãã
template <typename Alloc> struct allocator { template <typename Base> struct pack: public Base { typedef Alloc allocator ; }; };
ããã§ã
Alloc
ãã³ãã¬ãŒãåŒæ°ã¯ç¹å®ã®ã¢ãã±ãŒã¿ãŒã¯ã©ã¹ã§ããã
allocator
æ§é èªäœã¯ãªãã·ã§ã³ã®ååã§ãã 以äžã¯ããªãã·ã§ã³ãä»ããå²ãåœãŠã¿ã¹ã¯ã®å€èŠ³ã§ãã
cds::opt::allocator< std::allocator<int> >
ãããã®ãªãã·ã§ã³å®£èšã䜿çšãããšããªãã·ã§ã³ãã
traits
æ§é ãåéããã¡ã¿ãã¡ã³ã¯ã·ã§ã³ãç°¡åã«æ§ç¯ã§ããŸãã ãã®ããã»ã¹ã¯ãããã³ã°ãšåŒã°ããŸã ã
libcdsã«ã¯2çš®é¡ã®ãªãã·ã§ã³ããããŸãã
- äžè¬ãªãã·ã§ã³-å€ãã®ã³ã³ããã«é©çšå¯èœã ãã®ãããªãªãã·ã§ã³ã®å®£èšã¯
cds::opt
åå空éã«ãããæå¹ãªãªãã·ã§ã³å€ã¯åå空écds::opt::v
- ç¹å¥ãªãªãã·ã§ã³-ç¹å®ã®ã³ã³ããã¯ã©ã¹ã«ã®ã¿é©çšãããŸãã ãããã®å®£èšã¯ãç¹å®ã®ã³ã³ããã®åå空éã«ãããŸããããšãã°ã
cds::container::skip_list
åã³ã³ããã¯ã©ã¹ã®èª¬æã«ã¯ãæå¹ãªãªãã·ã§ã³ã®ãªã¹ããå«ãŸããŠããŸãã
æ¯èŒè¿°èª
ãããã®ã»ããã¿ã€ãã®å€ãã®ã³ã³ããã§ã¯ãèŠçŽ ãæ¯èŒããããã®è¿°èªãæå®ããå¿ èŠããããŸãã STLã§ã¯ãè¿°èª
std::less<T>
ãããã«äœ¿çšãããã¿ã€ã
T
èŠçŽ ã®ã¿ãæ¯èŒã§ããŸã
T
ããããéåžžã«ãã°ãã°äžäŸ¿ã§é«äŸ¡ã§ãã ããšãã°ã
std::string
åã¯
char const *
å€ãšæ¯èŒã§ããŸãããã®ãããªæ¯èŒã§ã¯ãäžæçãª
std::string
ãªããžã§ã¯ããäœæããå¿ èŠã¯ãããŸããã ã»ããã³ã³ããã®å Žåãã³ã³ããã«æ ŒçŽãããŠããã¿ã€ã
T
ã¯ãæ¯èŒã«å¿ èŠãªããŒãã£ãŒã«ããå«ãŸããŠããããšãå€ãããããŒããã¯ããŒã¿èªäœã§ãããæ€çŽ¢ã«ã¯äžåé¢äžããŸããã
以äžã®ããšãããlibcdsã¯ç°ãªãã¿ã€ãã®å€ãæ¯èŒã§ããé«åºŠãªè¿°èªã䜿çšããŸãã è¿°èªã¯ãªãã·ã§ã³ã«ãã£ãŠæå®ãããŸãã ããã«ãæ¡åŒµãããlessïŒãªãã·ã§ã³
cds::opt::less< typename Less >
ïŒãŸãã¯æ¡åŒµãããæ¯èŒïŒãªãã·ã§ã³
cds::opt::compare< typename Comparator >
ïŒãæ¯èŒè¿°éšãšããŠäœ¿çšã§ããŸãã æ¯èŒã¯æŽæ°å€ãè¿ããŸãã
-
cmp(a, b) < 0
a < b
å Žåa < b
cmp(a, b) < 0
-
cmp(a, b) == 0
a == b
å Žå -
cmp(a, b) > 0
a > b
å Žå
ã¡ãœããé¢æ°
std::string::compare
ãæ©èœããŸãã
æ¡åŒµè¿°èªïŒ
cds::opt::less< typename Less >
ãªãã·ã§ã³ã®
cds::opt::less< typename Less >
ãŸãã¯
cds::opt::compare< typename Comparator >
ãªãã·ã§ã³ã®
cds::opt::compare< typename Comparator >
ïŒã®äœæã¯ããªã次第ã§ãã 以äžã¯ã
Comparator
ãã¹ããªã³ã°æ¯èŒã§ã©ã®ããã«èŠãããã瀺ããŠããŸãã
struct string_cmp { int operator()(std::string const& s1, std::string const& s2) const { return s1.compare( s2 ); } int operator()(std::string const& s1, char const* s2) const { return s1.compare( s2 ); } int operator()(char const* s1, std::string const& s2) const { return âs2.compare( s1 ); } };
ã¢ãã±ãŒã¿ãŒ
cds::container
åå空éã®
cds::container
ã¯ããŒã¿ã®ã³ããŒãä¿åããããããããã®ãªãã·ã§ã³ã®1ã€ã¯
cds::opt::allocator
ããŒã¿çšã®ã¡ã¢ãªãå²ãåœãŠãããã®ã¢ãã±ãŒã¿ã§ãã äžéšã®ã³ã³ããã«ã¯ã2ã€ã®ã¢ãã±ãŒã¿ãªãã·ã§ã³ããããŸãã1ã€ã¯ããŒã¿é åžçšïŒ
cds::opt::node_allocator
ïŒããã1ã€ïŒ
cds::opt::allocator
ïŒ-è£å©ã³ã³ããæ§é ã«ã¡ã¢ãªãå²ãåœãŠãããã§ãã ããã©ã«ãã§ã¯ã
std::allocator<int>
ãšããŠäœ¿çšãã
std::allocator<int>
ã ã¢ãã±ãŒã¿ãŒã䜿çšããå Žåããã®ã€ã³ã¿ãŒãã§ãŒã¹ã¯
std::allocator
ãšåãã§ããå¿ èŠããã
std::allocator
ã
ã©ã€ãã©ãªã¯ãã¢ãã±ãŒã¿ã®2ã€ã®ããããã£ã«å€§ããäŸåããŠããŸãã
- åã¢ãã±ãŒã¿ãŒã«ã¯ãã¡ã¿é¢æ°
template <typename Other> struct rebind
ããããŸããããã«ãããç°ãªãã¿ã€ãã®Other
ã¢ãã±ãŒã¿ãŒãåæ§ç¯ã§ããŸãã ãã§ã«è¿°ã¹ãããã«ãããã©ã«ãã®std::allocator<int>
ã¯std::allocator<int>
ã§ã-ã³ã³ãããŒã¯ãrebind
é¢æ°ã䜿çšããŠint
åãå¿ èŠãªåã«å€æŽããŸã - ã¢ãã±ãŒã¿ãŒã¯ã°ããŒãã«ãªããžã§ã¯ãã§ãã ãã®èŠä»¶ã¯ãããã¯ããªãŒã³ã³ããèŠçŽ ã®ç©ççãªåãå€ããé
延ããã³ã³ãããªããžã§ã¯ãèªäœã®ç Žå£åŸã«çºçããå¯èœæ§ããããšããäºå®ããçããŠããŸãã ãããã£ãŠãSTLãšã¯ç°ãªããlibcdsã³ã³ãããŒã¯ã¢ãã±ãŒã¿ãŒãªããžã§ã¯ããžã®åç
§ãæ ŒçŽããããšã¯ãªããã¢ãã±ãŒã¿ãŒãªããžã§ã¯ããæå®ããã¡ãœããããããŸããã ã³ã³ããã¡ãœããå
ã§ã¡ã¢ãªãå²ãåœãŠãå¿
èŠãããå Žåãã¢ãã±ãŒã¿ã¯äžæãªããžã§ã¯ã
allocator_type().allocate( 1 )
ä»ããŠåŒã³åºãããŸãã åæ§ã«ãallocator_type().deallocate( p )
åŒã³åºãããšã§ã¡ã¢ãªã解æŸããallocator_type().deallocate( p )
ã ãªãªãŒã¹ãé 延ããã³ã³ãããªããžã§ã¯ãèªäœãããååšãããSMRã¢ã«ãŽãªãºã ããåŒã³åºããããšãã«ãã§ã«çºçããŠããå¯èœæ§ãããããšãå床泚ç®ãã䟡å€ããããŸãã
ç°¡åãªä»æ§
ãµããŒããããŠããã³ã³ãã€ã©ïŒ
- GCC 4.3以é
- MS Visual C ++ 2008以é
- Clang 3.0以éïŒGCCæšæºã©ã€ãã©ãªlibstdc ++ã䜿çšïŒ
ãµããŒããããŠãããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãšããã»ããµã¢ãŒããã¯ãã£ïŒ
- Windows x86ãamd64
- Linux x86ãamd64ãIntel ItaniumãSparc
- Solaris Sparc
- HP-UX Intel Itanium
ä»ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãŸãã¯ããã»ããµã¢ãŒããã¯ãã£ã®ãµããŒãã¯å¯èœã§ãããç¹ã«ã¿ãŒã²ããã³ã³ãã€ã©ãC ++ 11
atomic
ãµããŒãããŠããªãå Žåã¯ç°¡åã§ã¯ãããŸããã

ãããã«
ãã®èšäºãèªãã åŸãlibcdsã©ã€ãã©ãªã®äœ¿çšæ¹æ³ãæ確ã«ãªãããšãé¡ã£ãŠããŸãã ããã«ãããŒã¿æ§é ã©ã€ãã©ãªã«å®è£ ããåºæ¬çãªååãæ確ã«ããããšãè©Šã¿ãŸããã
ããã©ãŒãã³ã¹ã®åé¡ã«ã¯ãŸã£ãã觊ããŸããã æ¢ã«è¿°ã¹ãããã«ãããã©ãŒãã³ã¹ã¯ç¹å®ã®ã¿ã¹ã¯ãšç¹å®ã®ããŒããŠã§ã¢ã«é¢é£ããŠã®ã¿èª¬æã§ããŸãã çŸä»£ã®ããŒããŠã§ã¢ã¯ãããã¯ããªãŒã¢ã«ãŽãªãºã ã«å¯ŸããŠéåžžã«ç°ãªãæ 床ãæã£ãŠããŸãã1ã€ã¯åœŒããæ¯æãããã1ã€ã¯é·ãé説åŸããå¿ èŠããããããããŸããã Lock-free , « »: + , lock-free .
, : (shared) . , .
åç
§è³æ
[Des09] M.Desnoyers Low-Impact Operating System Tracing PhD Thesis,Chapter 6 «User-Level Implementations of Read-Copy Update»
[Des11] M.Desnoyers, P.McKenney, A.Stern, M.Dagenias, J.Walpole User-Level Implementations of Read-Copy Update
[Gid05] Anders Gidenstam, Marina Papatriantafilou and Philippas Tsigas Practical and Efficient Lock-Free Garbage Collection Based on Reference Counting
[Gid06] A.Gidenstam Algorithms for synchronization and consistency in concurrent system services , Chapter 5 «Lock-Free Memory Reclamation» Thesis for the degree of Doctor of Philosophy
[Her02] M. Herlihy, V. Luchangco, and M. Moir. The repeat offender problem: A mechanism for supporting dynamic-sized lockfree data structures Technical Report TR-2002-112, Sun Microsystems Laboratories, 2002
[Her05] M. Herlihy, V. Luchangco, P. Martin, and M. Moir. Nonblocking Memory Management Support for Dynamic_Sized Data Structures ACM Transactions on Computer Systems, Vol.23, No.2, May 2005
[Mic02] Maged M.Michael Safe memory reclamation for dynamic lock-free objects using atomic reads and writes
[Mic03] Maged M.Michael Hazard Pointers: Safe memory reclamation for lock-free objects
[Mic04] Andrei Alexandrescy, Maged Michael Lock-free Data Structures with Hazard Pointers
[Des11] M.Desnoyers, P.McKenney, A.Stern, M.Dagenias, J.Walpole User-Level Implementations of Read-Copy Update
[Gid05] Anders Gidenstam, Marina Papatriantafilou and Philippas Tsigas Practical and Efficient Lock-Free Garbage Collection Based on Reference Counting
[Gid06] A.Gidenstam Algorithms for synchronization and consistency in concurrent system services , Chapter 5 «Lock-Free Memory Reclamation» Thesis for the degree of Doctor of Philosophy
[Her02] M. Herlihy, V. Luchangco, and M. Moir. The repeat offender problem: A mechanism for supporting dynamic-sized lockfree data structures Technical Report TR-2002-112, Sun Microsystems Laboratories, 2002
[Her05] M. Herlihy, V. Luchangco, P. Martin, and M. Moir. Nonblocking Memory Management Support for Dynamic_Sized Data Structures ACM Transactions on Computer Systems, Vol.23, No.2, May 2005
[Mic02] Maged M.Michael Safe memory reclamation for dynamic lock-free objects using atomic reads and writes
[Mic03] Maged M.Michael Hazard Pointers: Safe memory reclamation for lock-free objects
[Mic04] Andrei Alexandrescy, Maged Michael Lock-free Data Structures with Hazard Pointers
ããã¯ããªãŒã®ããŒã¿æ§é
éå§ãã
åºæ¬ïŒ
äžïŒ
å€ããïŒ
åºæ¬ïŒ
- ååæ§ããã³ååããªããã£ã
- èšæ¶ã®å£ã¯ã©ãããæ¥ãã®ã§ããïŒ
- ã¡ã¢ãªã¢ãã«
äžïŒ
- ã¡ã¢ãªç®¡çã¹ããŒã
- RCU
- ã¹ã¿ãã¯ã®é²å
- å¥ã®è«æ
- ãã¥ãŒåæ
- 䞊è¡ãããïŒãŠã©ãŒã ã¢ãã
- 䞊è¡ãããïŒåããã·ã¥ãåæ§ç¯ãªã
- 䞊è¡ãããïŒãªã¹ããã¹ããã
- äžèŽãããïŒæš
- ã€ãã¬ãŒã¿ïŒãã«ãã¬ãã«é å
- å埩å¯èœãªãªã¹ã
å€ããïŒ