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

並行四方山話/tales_of_concurrency

fuzyco
January 09, 2019

 並行四方山話/tales_of_concurrency

社内の新年会で話した資料です。
このプレゼンテーションは
- カーネルスレッドとグリーンスレッドの違い
- JVMのスレッド
- Actorモデル
- Goroutine
の内容を含みます。

This presentation includes these topics below:
- Difference between kernel thread and green thread
- JMV Thread
- Actor Model
- Goroutine

fuzyco

January 09, 2019
Tweet

More Decks by fuzyco

Other Decks in Technology

Transcript

  1. ϓϩηε  ϓϩάϥϜΛىಈͨ͠ͱ͖ʹͰ͖Δ w ΞυϨεۭؒ w ؔ࿈ͷ͋Δ͢΂ͯͷঢ়ଶ ϨδελͳͲ  w

    ֤छͷ৘ใ ϓϩηε*%ͳͲ  w ϓϩηεؒ௨৴ʹ࢖ΘΕΔɺͦͷଞͷϦιʔε ϝοηʔδΩϡʔͳͲ ϓϩηε
  2. ૝ఆ؀ڥ  Ϣ ɹ β ɹ Χ ɹ ω ϧ

    ۭ ؒ ۭ ؒ ʔ ʔ ʔ $16 $16 ΞϓϦέʔγϣϯϓϩηε 04 ϋʔυ΢ΣΞ ҰͭͷΞϓϦέʔγϣϯϓϩηε͕ϚϧνεϨουͰಈ͘
  3. ΧʔωϧεϨου  Χʔωϧεέδϡʔϥʔ $16 $16 Χ ɹ ω ϧ 04͕ఏڙ͢ΔεϨου

    ۭ ؒ ʔ 04ͷΧʔωϧ಺ͷ εέδϡʔϥʔʹ؅ཧ͞ΕΔ
  4. ϢʔβʔεϨου  άϦʔϯεϨουͱ΋͍͏ Ϣ ɹ β ɹ Χ ɹ ω

    ϧ ۭ ؒ ۭ ؒ ʔ ʔ ʔ Ϣʔβʔεέδϡʔϥʔ ϥϯλΠϜʢݴޠʣ ͕ఏڙ͢ΔεϨου ΞϓϦέʔγϣϯϓϩηε ϥϯλΠϜͷ εέδϡʔϥʔʹ؅ཧ͞ΕΔ
  5. /ํࣜ  Χʔωϧεέδϡʔϥʔ $16 $16 Ϣ ɹ β ɹ Χ

    ɹ ω ϧ ۭ ؒ ۭ ؒ ʔ ʔ ʔ Ϣʔβʔεέδϡʔϥʔ /ݸͷϢʔβʔεϨουɿݸͷΧʔωϧεϨου ΞϓϦέʔγϣϯϓϩηε ΞϓϦέʔγϣϯϓϩηε্ͷ̍ͭҎ্ͷ ϢʔβʔεϨου͕ɺ ̍ͭͷΧʔωϧεϨουΛ࢖͏ ෳ਺͸ෆՄ ̍ϓϩηεʹ̍ΧʔωϧεϨουͷΈ
  6. ํࣜ  Χʔωϧεέδϡʔϥʔ $16 $16 Ϣ ɹ β ɹ Χ

    ɹ ω ϧ ۭ ؒ ʔ ʔ ʔ ۭ ؒ ̍ݸͷ࣮ߦεϨουɿ̍ݸͷΧʔωϧεϨου ΞϓϦέʔγϣϯϓϩηε͸ׂΓ౰ͯΒΕͨ ΧʔωϧεϨουͰॲཧΛ࣮ߦ͢Δ ΞϓϦέʔγϣϯϓϩηε͸ɺ $16ίΞͷ਺͚ͩΧʔωϧεϨουΛ ಉ࣌ʹ࢖͑Δʢฒߦ͔ͭฒྻ͕Մೳ ΞϓϦέʔγϣϯϓϩηε ̍ϓϩηεʹෳ਺ΧʔωϧεϨου͕Մೳ
  7. ./ํࣜ  Χʔωϧεέδϡʔϥʔ $16 $16 Ϣʔβʔεέδϡʔϥʔ Ϣ ɹ β ɹ

    Χ ɹ ω ϧ ۭ ؒ ۭ ؒ ʔ ʔ ʔ .ݸͷϢʔβʔεϨουɿ/ݸͷΧʔωϧεϨου ΞϓϦέʔγϣϯϓϩηε ͱ/ͷϋΠϒϦουܕ ϓϩηεʹෳ਺ΧʔωϧεϨου͕ՄೳͰɺ ͦΕΒΛϢʔβʔεϨουͰڞ༗ͯ͠࢖͏Πϝʔδ ʢฒߦ͔ͭฒྻ͕Մೳ
  8. ࣮ߦํࣜͷൺֱ  /  ./ ϝϦοτ ίϯςΩετ εΠον͕଎͍ Ϛγϯ্ͷίΞ Λશͯ࢖͑Δ

    ྑ͍ͱ͜ΖͲΓ σϝϦοτ ϚϧνίΞΛ ੜ͔ͤͳ͍ ίϯςΩετ εΠον͕஗͍ εέδϡʔϥʔ ͕ෳࡶʹͳΔ
  9. +7.ͷεϨου  val thread = new Thread() <ࢀߟ>KELIPUTQPUTSDPTMJOVYWNPT@MJOVYDQQ ಺෦Ͱ͸ΧʔωϧεϨουΛੜ੒͍ͯ͠Δ Χʔωϧۭؒ

    JOUSFUQUISFBE@DSFBUF UJE BUUS  WPJE  WPJE UISFBE@OBUJWF@FOUSZ  UISFBE  val executorService = Executors.newFixedThreadPool(4) ͭͷΧʔωϧ εϨουͷϓʔϧΛੜ੒
  10. HPSPVUJOFͷεέδϡʔϦϯά  εέδϡʔϦϯά͸./ํࣜ ෳ਺ͷHPSPVUJOF͕ ҰͭͷΧʔωϧεϨουΛ ͍࣋ͬͯΔΠϝʔδ Χʔωϧεέδϡʔϥʔ $16 $16 HPSPVUJOFεέδϡʔϥʔ

    ΧʔωϧεϨουΛҙࣝͤͣʹ HPଆͰHPSPVUJOFΛߴ଎ʹ੾Γସ͑ͯ ฒߦॲཧͷੑೳΛ্͍͛ͯΔ HPΞϓϦέʔγϣϯ ෳࡶͳεέδϡʔϦϯά͸ HPଆͰٵऩ͍ͯ͠Δ
  11. HPSPVUJOFͷ ίϯςΩετεΠον࣌ؒ  ίϯςΩετεΠονʹཁ͢Δ࣌ؒͷൺֱྫ Χʔωϧ εϨου HPSPVUJOF ࣌ؒ<ЖT>  

      <Ҿ༻>(PݴޠʹΑΔฒߦॲཧ ίϯςΩετεΠονΛΧʔωϧεϨουΑΓ΋ਝ଎ʹߦ͑Δ
  12. "LLB"DUPSʹ͓͚Δ εέδϡʔϦϯά  Χʔωϧεέδϡʔϥʔ +7.ϓϩηε $16 $16 %JTQBUDIFS ํ͕ࣜͩɺ+7.ϓϩηεͰ͸ͳ͘ɺ ΞΫλʔ

    ܰྔϓϩηε ͕ ΧʔωϧεϨουΛ࢖ͬͯॲཧΛߦ͏ %JTQBUDIFS͕ ϢʔβʔεέδϡʔϥʔͷΑ͏ʹৼΔ෣͏ Πϝʔδ
  13. ·ͱΊ  +7.ͷ εϨου HPSPVUJOF "LLB"DUPS ࣮ଶ Χʔωϧ εϨου Ϣʔβʔ

    εϨου ܰྔϓϩηε ΦϒδΣΫτ αΠζ .# ,# ,# ࣮ߦํࣜ  ./