Upgrade to Pro — share decks privately, control downloads, hide ads and more …

select文の内部実装見つけました

3933b943fb70400bbc26f3cb78d8204c?s=47 H.Saki
August 11, 2021

 select文の内部実装見つけました

21/8/11 GeekGig #1 〜Goと私の一年〜にて発表

https://showcase-gig.connpass.com/event/217914/

3933b943fb70400bbc26f3cb78d8204c?s=128

H.Saki

August 11, 2021
Tweet

Transcript

  1. select文の内部実装見つけました GeekGig #1, AUG 11 2021 さき(H.Saki) @saki-engineer

  2. About Me 自己紹介 l ͖͞ )4BLJ ◦ ౦େ޻ֶ෦ ˠ ࠓ೥͔Β৽ࣾձਓ

    ݚमத ◦ 5XJUUFS!TBLJFOHJOFFS l աڈͷ੒Ռ෺ FUDʜ
  3. TFMFDUจͰ͸ɺதʹDBTFจΛॻ͘͜ͱͰॲཧͷ෼ذΛ࣮ݱ͍ͯ͠Δɻ Select statements select文 var i1, i2 int var ch1,

    ch2 chan int select { case i1 = <-ch1: print("received ", i1, " from c1∖n") case ch2 <- i2: print("sent ", i2, " to c2∖n") default: print("no communication∖n") } νϟωϧDI͔Βͷड৴͕Մೳͳͱ͖࣮ߦ νϟωϧDI΁ͷૹ৴͕Մೳͳͱ͖࣮ߦ ͍ͣΕͰ΋ͳ͍৔߹ʹ࣮ߦ EFGBVMUDBTF͕ͳ͚Ε͹ϒϩοΫ
  4. runtime/select.go runtime/select.go ߦ໨ʹʮ͜ͷϑΝΠϧʹ͸TFMFDUจͷ࣮૷ؚ͕·Ε͍ͯ·͢ʯͱͷهࡌ͋Γ

  5. runtime/select.go runtime/select.go TFMFDUจຊମͷهड़͸ɺ-ͷ GVOD TFMFDUHP ͰߦΘΕ͍ͯΔɻ // selectgo implements the

    select statement. func selectgo(cas0 *scase, order0 *uint16, pc0 *uintptr, nsends, nrecvs int, block bool) (int, bool) { // (略) // 400行くらいある }
  6. None
  7. ͪΐͬͱԿݴͬͯΔ͔Θ͔Μͳ͍

  8. ͜Μͳͱ͖͸ίϝϯτʹண໨͠Α͏ʂ

  9. Implementation of select statement select文の実装 ϒϩοΫ͠ͳͯ͘Α͍৔߹͔Β࣮૷͍ͯ͠Δ͜ͱ͕֬ೝͰ͖Δɻ TFMFDU͢Δର৅ͷத͔Βૹड৴Ͱ͖Δ νϟωϧ͕ͳ͍͔Λ୳͍ͯ͠ΔͬΆ͍ l νϟωϧ͔Βड৴ՄˠSFDW

    l όοϑΝ͔Βड৴ՄˠCVGSFDW l νϟωϧDMPTFࡁΈˠSDMPTF ͔ͳʁͱ͍͏Ծઆ͕༰қʹཱͭ
  10. Implementation of select statement select文の実装 ͦͷ࣍ʹɺϒϩοΫʹೖΔ৔߹ͷॲཧΛॻ͍͍ͯΔɻ ૹड৴Ͱ͖Δνϟωϧ͕ͳ ͔ͬͨͱ͖ͷॲཧ͔ͳʁ HPQBSLؔ਺ͰҎԼͷॲཧΛ࣮ߦ͠ɺTFMFDUจͷCMPDLΛ࣮ݱ 

    TFMFDUจΛ࣮ߦ͍ͯ͠Δΰʔϧʔνϯͷঢ়ଶΛSVOOJOH͔ΒXBJUJOHʹมߋ  ֘౰ΰʔϧʔνϯΛεϨου͔ΒҰ୴੾Γ཭͢
  11. Summary まとめ l TFMFDUจຊମͷ࣮૷͸SVOUJNFTFMFDUHPͷதͷTFMFDUHPؔ਺ ◦ େମͷ(Pͷجװػೳ͸SVOUJNFύοέʔδͷதʹ͋Δ l ίʔυΛૉ௚ʹಡΈղ͔ͳͯ͘΋ɺ࣮૷ͷେ࿮Λ୳Δ͜ͱ͸Ͱ͖Δ ख͕͔ΓʹͳΔͷ͸ҎԼ ◦

    ίϝϯτ ◦ ม਺ɾఆ਺ɾؔ਺໊ ◦ ߏ଄ମͷϑΟʔϧυ໊ ◦ ϥϕϧ໊ l ΈΜͳSVOUJNFύοέʔδΛಡ΋͏;&ˑ
  12. 5IBOLZPVGPSMJTUFOJOH