Slide 1

Slide 1 text

ԘҪඒ࡙!DPF@ .BS 'VLVPLBSCճ-5େձ Β͘Β͘3BDUPS

Slide 2

Slide 2 text

'VLVPLBSC ͓ΊͰͱ͏͍͟͝·͢ʂ

Slide 3

Slide 3 text

ຊ೔ͷൃදʹ͍ͭͯ ɹฒߦฒྻϓϩάϥϛϯάઈࢍษڧதͰ͢ɻ ɹٕज़తࢦఠͳͲ͓଴͍ͪͯ͠·͢ɻ 8*1

Slide 4

Slide 4 text

ຊ೔ͷൃදʹ͍ͭͯ ɹXBSOJOH3BDUPSJTFYQFSJNFOUBM ɹBOEUIFCFIBWJPSNBZDIBOHFJOGVUVSFWFSTJPOTPG3VCZ ɹ"MTPUIFSFBSFNBOZJNQMFNFOUBUJPOJTTVFT ɹ3BDUPS͸3VCZͷ࣮ݧతػೳͳͷͰɺ ɹࠓޙ࢓༷͕มΘΔ͔΋͠Ε·ͤΜɻ 8*1 ͱ͍͑͹ʜ

Slide 5

Slide 5 text

ࣗݾ঺հ ԘҪඒ࡙ ͓͍͠ !DPF@ ɹ8FCϓϩάϥϚˠ ɹ'VLVPLBSCੜ·Εɺ"TBLVTBSCҭͪ ɹ࠷ۙ3VCZͷ৽ػೳɾ3BDUPS͕ؾʹͳ͍ͬͯ·͢

Slide 6

Slide 6 text

ࣗݾ঺հ ԘҪඒ࡙ ͓͍͠ !DPF@ ɹ8FCϓϩάϥϚˠ ɹ'VLVPLBSCੜ·Εɺ"TBLVTBSCҭͪ ɹ࠷ۙ3VCZͷ৽ػೳɾ3BDUPS͕ؾʹͳ͍ͬͯ·͢ ‐ࠓ೔ͷ͓࿩

Slide 7

Slide 7 text

3BDUPSʹؔ͢ΔυΩϡϝϯτ 3BDUPS3VCZT"DUPSMJLFDPODVSSFOUBCTUSBDUJPO IUUQTHJUIVCDPNSVCZSVCZCMPCNBTUFSEPDSBDUPSNE 3BDUPS 3VCZ%PDPSH IUUQTSVCZEPDPSHDPSF3BDUPSIUNM 3VCZͷ3BDUPSΛࣗຫ͍ͨ͠ ΫοΫύου։ൃऀϒϩά ɹIUUQTUFDIMJGFDPPLQBEDPNFOUSZ 3VCZͷ3BDUPSʹ͍ͭͯ ۜ࠲3BJMT IUUQXXXBUEPUOFUdLPBDUJWJUJFT@HJO[BSBJMTQEG

Slide 8

Slide 8 text

3BDUPSʹؔ͢ΔυΩϡϝϯτ 3BDUPS3VCZT"DUPSMJLFDPODVSSFOUBCTUSBDUJPO IUUQTHJUIVCDPNSVCZSVCZCMPCNBTUFSEPDSBDUPSNE 3BDUPS 3VCZ%PDPSH IUUQTSVCZEPDPSHDPSF3BDUPSIUNM 3VCZͷ3BDUPSΛࣗຫ͍ͨ͠ ΫοΫύου։ൃऀϒϩά ɹIUUQTUFDIMJGFDPPLQBEDPNFOUSZ 3VCZͷ3BDUPSʹ͍ͭͯ ۜ࠲3BJMT IUUQXXXBUEPUOFUdLPBDUJWJUJFT@HJO[BSBJMTQEG

Slide 9

Slide 9 text

ͨͷ͍͠ฒߦฒྻϓϩάϥϛϯά Ҿ༻ɿ3VCZͷ3BDUPSʹ͍ͭͯ ɹɹɹIUUQXXXBUEPUOFUdLPBDUJWJUJFT@HJO[BSBJMTQEG

Slide 10

Slide 10 text

ैདྷͷ3VCZʹ૊Έࠐ·Ε͍ͯͨ5ISFBEͱൺֱͯ͠ 3BDUPS͕׎͑Δʮͨͷ͠͞ʯͱ͸ͲΜͳ΋ͷʁ

Slide 11

Slide 11 text

ͦΕΛମݧ͢ΔͨΊɺ5ISFBEͱ3BDUPSͰ ಉ͡ॲཧΛߦ͏ϓϩάϥϜΛ ॻ͖͘Β΂ͯΈ·ͨ͠

Slide 12

Slide 12 text

ͦΕΛମݧ͢ΔͨΊɺ5ISFBEͱ3BDUPSͰ 1SPEVDFS$POTVNFSύλʔϯΛ ॻ͖͘Β΂ͯΈ·ͨ͠ ࠓճͷίʔυ͸ҎԼʹVQ͍ͯ͠·͢ IUUQTHJUIVCDPNTIJPJNNUJMUSFFNBTUFSBDUJWJUJFT@GVLVPLB@QSPEVDFS@DPOTVNFS

Slide 13

Slide 13 text

ࢀরɿ+BWBݴޠͰֶͿσβΠϯύλʔϯೖ໳ϚϧνεϨουฤɹ݁৓ߒஶɹୈষ1SPEVDFS$POTVNFS σʔλΛૹ৴͢Δ εϨου σʔλΛड৴͢Δ εϨου σʔλ σʔλΛ தܧ఺ʹ౉͢ 1SPEVDFS$POTVNFSύλʔϯ σʔλΛૹ৴͢ΔεϨουͱσʔλΛड৴͢ΔεϨουͷؒʹ தܧ఺Λઃ͚Δ͜ͱʹΑΓɺ҆શʹޮ཰Α͘σʔλΛड͚౉͢ தܧ఺ σʔλΛ தܧ఺͔ΒऔΔ ͓ޓ͍ͷεϨου͸͓ޓ͍޷͖ͳλΠϛϯάͰಈ࡞͢Δ͜ͱ͕Ͱ͖Δ

Slide 14

Slide 14 text

ࢀরɿ+BWBݴޠͰֶͿσβΠϯύλʔϯೖ໳ϚϧνεϨουฤɹ݁৓ߒஶɹୈষ1SPEVDFS$POTVNFS σʔλ σʔλΛ தܧ఺ʹ౉͢ 1SPEVDFS$POTVNFSύλʔϯ σʔλΛૹ৴͢ΔεϨουͱσʔλΛड৴͢ΔεϨουͷؒʹ தܧ఺Λઃ͚Δ͜ͱʹΑΓɺ҆શʹޮ཰Α͘σʔλΛड͚౉͢ σʔλΛ தܧ఺͔ΒऔΔ ͓ޓ͍ͷεϨου͸͓ޓ͍޷͖ͳλΠϛϯάͰಈ࡞͢Δ͜ͱ͕Ͱ͖Δ 1SPEVDFS $POTVNFS $IBOOFM

Slide 15

Slide 15 text

ࠓճͷϓϩάϥϜͷྲྀΕ 1SPEVDFS $POTVNFS $IBOOFM ൪߸ σʔλʹ࠾൪͢Δ QSPEVDU σʔλΛϓʔϧ͢Δ σʔλΛ౉͢ σʔλΛऔΔ QSPEVDU ࠾൪ػ QSPEVDU QSPEVDU

Slide 16

Slide 16 text

ϓϩάϥϜͷ࣮ߦ݁Ռ ྫ ᶃ1͕$IBOOFMʹOPΛ౉͢ ᶄ1͕$IBOOFMʹOPΛ౉͢ ᶅ$͕$IBOOFM͔ΒOPΛऔΔ ᶆ$͕$IBOOFM͔ΒOPΛऔΔ ᶇ1͕$IBOOFMʹOPΛ౉͢ ᶈ$͕$IBOOFM͔ΒOPΛऔΔ ᶉ1͕$IBOOFMʹOPΛ౉͢ ᶊ1͕$IBOOFMʹOPΛ౉͢ ᶋ$͕$IBOOFM͔ΒOPΛऔΔ ʜ ͭͷ1SPEVDFSεϨουͱ̏ͭͷ$POTVNFSεϨου͕ ͦΕͧΕಉ࣌ʹಈ࡞͢Δ৔߹ͷྫ

Slide 17

Slide 17 text

5ISFBEΛ࢖࣮ͬͨ૷ ˞ͨͩ͠ࠓճ(7-ͷ͜ͱ͸ߟ͑ͳ͍΋ͷͱ͠·͢

Slide 18

Slide 18 text

5ISFBEΛ࢖͏ϓϩάϥϜͷશମ૾ class Producer # … class Consumer # … class Numbering # … class Channel # … channel = Channel.new(3) producers = 3.times.map { Thread.new { # … } } consumers = 3.times.map { Thread.new { # … } } producers.each(&:join) consumers.each(&:join) $IBOOFMΫϥε ࠾൪ػΫϥε 1SPEVDFSΫϥε $POTVNFSΫϥε ϝΠϯϓϩάϥϜ

Slide 19

Slide 19 text

ϝΠϯϓϩάϥϜͷ࣮૷ channel = Channel.new(3) producers = 3.times.map { |i| Thread.new do Producer.new(“P-#{i + 1}”, channel).run end } consumers = 3.times.map { |i| Thread.new do Consumer.new(“C-#{i + 1}”, channel).run end } producers.each(&:join) consumers.each(&:join) QSPEVDUΛͭϓʔϧ͢Δ$IBOOFMΛੜ੒ ͭͷεϨουͰ 1SPEVDFSΦϒδΣΫτΛ ੜ੒͠ɺՔಇͤ͞Δ ͭͷεϨουͰ $POTVNFSΦϒδΣΫτΛ ੜ੒͠ɺՔಇͤ͞Δ

Slide 20

Slide 20 text

ϝΠϯϓϩάϥϜͷ࣮૷ channel = Channel.new(3) producers = 3.times.map { |i| Thread.new do Producer.new(“P-#{i + 1}”, channel).run end } consumers = 3.times.map { |i| Thread.new do Consumer.new(“C-#{i + 1}”, channel).run end } producers.each(&:join) consumers.each(&:join) Ҿ਺ͱ֤ͯ͠εϨουͷ໊લͱ $IBOOFMΛ౉͢ ֤εϨουͷ࣮ߦΛ଴ͪ߹ΘͤΔ

Slide 21

Slide 21 text

1SPEVDFSΫϥεͷ࣮૷ class Producer def initialize(name, channel) Thread.current.name = name @channel = channel end def run loop do product_no = Numbering.issue @channel.put "Product no. #{product_no}" end end end ࠾൪ػ͔Β QSPEVDU൪߸Λऔಘ͢Δ ࠾൪ͨ͠QSPEVDUΛ$IBOOFMʹஔ͘ # εϨουͷ໊લΛอଘ # ChannelΦϒδΣΫτ

Slide 22

Slide 22 text

࠾൪ػΫϥεͷ࣮૷ class Numbering @@product_no = 0 def self.issue Mutex.new.synchronize do @@product_no += 1 end end end QSPEVDU൪߸ΛΧ΢ϯτΞοϓ͠ɺฦ͢ .VUFYTZODISPOJ[F ಉ࣌ʹΞΫηεͰ͖ΔͷΛ εϨουʹ੍ݶ͢Δ͜ͱͰ ةݥྖҬΛอޢ͢Δ ෳ਺ͷ1SPEVDFSεϨου͔Β ಉ࣌ʹΞΫηε͞ΕΔͨΊ ڝ߹͠ͳ͍Α͏ϩοΫΛ͔͚Δ

Slide 23

Slide 23 text

$IBOOFMΫϥεͷ࣮૷ class Channel def initialize(size) @products = [] @size = size @mutex = Mutex.new @cond = ConditionVariable.new end def put(product) # … end def take # … end end 1SPEVDFSΦϒδΣΫτͷதͰݺ͹ΕΔϝιου QSPEVDUΛϓʔϧʹೖΕΔͨΊͷ΋ͷ $POTVNFSΦϒδΣΫτͷதͰݺ͹ΕΔϝιου QSPEVDUΛϓʔϧ͔ΒऔΓग़ͨ͢Ίͷ΋ͷ # mutex # ৚݅ม਺ # Channelͷϓʔϧ # Channel͕ಉ࣌ʹϓʔϧͰ͖Δ࠷େ਺

Slide 24

Slide 24 text

$IBOOFMΫϥεͷ࣮૷ QVUϝιου class Channel def initialize(size) # … def put(product) @mutex.synchronize do while @products.size >= @size @cond.wait(@mutex) end # … end end def take # … end $POEJUJPO7BSJBCMFXBJU ৚͕݅ຬͨ͞ΕΔ·Ͱ NVUFYͷϩοΫΛղআ͠ɺ ॲཧΛ଴ػͤ͞Δ ϓʔϧʹۭ͖͕ͳ͍৔߹ɺ QSPEVDUΛϓʔϧʹೖΕΔ ͜ͱ͕Ͱ͖ͳ͍

Slide 25

Slide 25 text

$IBOOFMΫϥεͷ࣮૷ QVUϝιου class Channel def initialize(size) # … def put(product) @mutex.synchronize do while @products.size >= @size @cond.wait(@mutex) end # … end end def take # … end ϓʔϧʹۭ͖͕ͳ͍৔߹ɺ QSPEVDUΛϓʔϧʹೖΕΔ ͜ͱ͕Ͱ͖ͳ͍ ‎৚݅ม਺Λ࢖ͬͯ ϓʔϧʹۭ͖͕Ͱ͖Δ·Ͱ ͜͜ͰॲཧΛ଴ػ͢Δ $POEJUJPO7BSJBCMFXBJU ৚͕݅ຬͨ͞ΕΔ·Ͱ NVUFYͷϩοΫΛղআ͠ɺ ॲཧΛ଴ػͤ͞Δ

Slide 26

Slide 26 text

$IBOOFMΫϥεͷ࣮૷ QVUϝιου class Channel def initialize(size) # … def put(product) @mutex.synchronize do while @products.size >= @size @cond.wait(@mutex) end # … end end def take # … end ϓʔϧʹۭ͖͕Ͱ͖Δͷ͸ ͍ͭʁ

Slide 27

Slide 27 text

class Channel def initialize(size) # … def put(product) # … def take @mutex.synchronize do # … product = @products.pop @cond.signal product end end end $IBOOFMΫϥεͷ࣮૷ UBLFϝιου $POTVNFSΦϒδΣΫτͷதͰ UBLFϝιου͕ݺ͹ΕΔ ‎ϓʔϧ͔ΒQSPEVDU͕औΓग़͞ΕΔ ‎ϓʔϧʹۭ͖͕Ͱ͖Δ

Slide 28

Slide 28 text

$IBOOFMΫϥεͷ࣮૷ UBLFϝιου class Channel def initialize(size) # … def put(product) # … def take @mutex.synchronize do # … product = @products.pop @cond.signal product end end end $POEJUJPO7BSJBCMFTJHOBM ॲཧͷ଴ػΛղআ͠ɺ ࠶ͼϩοΫΛऔಘͰ͖ΔΑ͏ ৚݅ม਺΁௨஌ΛૹΔ ϓʔϧʹۭ͖͕Ͱ͖ͨ͜ͱΛ ৚݅ม਺΁௨஌͢Δ

Slide 29

Slide 29 text

$IBOOFMΫϥεͷ࣮૷ UBLFϝιου class Channel def initialize(size) # … def put(product) # … def take @mutex.synchronize do # … product = @products.pop @cond.signal product end end end $POEJUJPO7BSJBCMFTJHOBM ॲཧͷ଴ػΛղআ͠ɺ ࠶ͼϩοΫΛऔಘͰ͖ΔΑ͏ ৚݅ม਺΁௨஌ΛૹΔ ϓʔϧʹۭ͖͕Ͱ͖ͨ͜ͱΛ ৚݅ม਺΁௨஌͢Δ ‎QVUϝιουͷ଴ػΛղআ͢Δ

Slide 30

Slide 30 text

$IBOOFMΫϥεͷ࣮૷ ࠶ͼQVUϝιου class Channel def initialize(size) # … def put(product) @mutex.synchronize do while @products.size >= @size @cond.wait(@mutex) end @products.push product puts "#{Thread.current.name} produces #{product}." @cond.signal end end def take # … end ॲཧΛ࠶։ͨ͠Β QSPEVDUΛϓʔϧʹೖΕΔ

Slide 31

Slide 31 text

$IBOOFMΫϥεͷ࣮૷ ࠶ͼQVUϝιου class Channel def initialize(size) # … def put(product) @mutex.synchronize do while @products.size >= @size @cond.wait(@mutex) end @products.push product puts "#{Thread.current.name} produces #{product}." @cond.signal end end def take # … end QVUϝιουͷதͰ΋ ৚݅ม਺΁ͷ௨஌Λߦͳ͍ͬͯΔ

Slide 32

Slide 32 text

$IBOOFMΫϥεͷ࣮૷ ࠶ͼUBLFϝιου class Channel def initialize(size) # … def put(product) # … def take @mutex.synchronize do while @products.size <= 0 @cond.wait(@mutex) end product = @products.pop @cond.signal product end end end ˞UBLFϝιου͸QVUϝιουΛ ɹ൓సͤͨ͞Α͏ͳॲཧΛߦͳ͍ͬͯΔ ϓʔϧ͕ۭͰ͋Δ৔߹ɺ ϓʔϧ͔ΒQSPEVDUΛऔΔ ͜ͱ͕Ͱ͖ͳ͍ ‎৚݅ม਺Λ࢖ͬͯ ϓʔϧʹQSPEVDU͕ೖΔ·Ͱ ͜͜ͰॲཧΛ଴ػ͢Δ ॲཧΛ࠶։ͨ͠Β QSPEVDUΛϓʔϧ͔ΒऔΓग़͢

Slide 33

Slide 33 text

$POTVNFSΫϥεͷ࣮૷ class Consumer def initialize(name, channel) Thread.current.name = name @channel = channel end def run loop do product = @channel.take puts "#{Thread.current.name} consumes #{product}." end end end # εϨουͷ໊લΛอଘ # ChannelΦϒδΣΫτ $IBOOFM͔ΒQSPEVDUΛऔΓग़͢

Slide 34

Slide 34 text

$POTVNFSΫϥεͷ࣮૷ class Consumer def initialize(name, channel) Thread.current.name = name @channel = channel end def run loop do product = @channel.take puts "#{Thread.current.name} consumes #{product}." end end end $IBOOFM͔ΒQSPEVDUΛऔΓग़͢ ׬੒ʂ # εϨουͷ໊લΛอଘ # ChannelΦϒδΣΫτ

Slide 35

Slide 35 text

5ISFBEΛ࢖࣮ͬͨ૷ͷͨͷ͘͠ͳ͍ͱ͜Ζ ?ొ৔ਓ෺͕ଟ͍ εϨουɺNVUFYɺ৚݅ม਺ ?ϧʔϧ͕ଟ͍ ᶃσʔλ΁ͷॻ͖ࠐΈΛߦ͏ͱ͖͸ ɾڝ߹Λ๷͙ͨΊʹNVUFYΛ࢖ͬͯϩοΫΛ͔͚Δ ᶄ$IBOOFMͷঢ়ଶʹԠͯ͡৚݅ม਺ͰॲཧΛ଴ػͤ͞Δ ᶅ଴ػͤͨ͞ॲཧΛ࠶։͢Δͱ͖͸৚݅ม਺΁௨஌͢Δ

Slide 36

Slide 36 text

5ISFBEΛ࢖࣮ͬͨ૷ͷͨͷ͘͠ͳ͍ͱ͜Ζ ?ొ৔ਓ෺͕ଟ͍ εϨουɺNVUFYɺ৚݅ม਺ ?ϧʔϧ͕ଟ͍ ᶃσʔλ΁ͷॻ͖ࠐΈΛߦ͏ͱ͖͸ ɾڝ߹Λ๷͙ͨΊʹNVUFYΛ࢖ͬͯϩοΫΛ͔͚Δ ᶄ$IBOOFMͷঢ়ଶʹԠͯ͡৚݅ม਺ͰॲཧΛ଴ػͤ͞Δ ᶅ଴ػͤͨ͞ॲཧΛ࠶։͢Δͱ͖͸৚݅ม਺΁௨஌͢Δ ϧʔϧͷద༻࿙Ε͕͋ΔͱࠔΔʜ ϧʔϧΛద੾ʹద༻͢Δͷ͕೉͍͠ʜ

Slide 37

Slide 37 text

3BDUPSΛ࢖࣮ͬͨ૷

Slide 38

Slide 38 text

3BDUPSΛ࢖͏ϓϩάϥϜͷશମ૾ class Producer # … class Consumer # … channel = Ractor.new { # … } numbering = Ractor.new { # … } producers = 3.times.map { Ractor.new { # … } } consumers = 3.times.map { Ractor.new { # … } } producers.each(&:take) consumers.each(&:take) 1SPEVDFSΫϥε $POTVNFSΫϥε $IBOOFM3BDUPS ϝΠϯϓϩάϥϜ ࠾൪ػ3BDUPS

Slide 39

Slide 39 text

ϝΠϯϓϩάϥϜͷ࣮૷ producers = 3.times.map { |i| Ractor.new(channel, numbering, name: "P-#{i + 1}") do |ch, num| Producer.new(ch, num).run end } consumers = 3.times.map { |i| Ractor.new(channel, name: "C-#{i + 1}") do |ch| Consumer.new(ch).run end } producers.each(&:take) consumers.each(&:take) ͭͷ3BDUPSͰ 1SPEVDFSΦϒδΣΫτΛ ੜ੒͠ɺՔಇͤ͞Δ ͭͷ3BDUPSͰ $POTVNFSΦϒδΣΫτΛ ੜ੒͠ɺՔಇͤ͞Δ

Slide 40

Slide 40 text

ϝΠϯϓϩάϥϜͷ࣮૷ producers = 3.times.map { |i| Ractor.new(channel, numbering, name: "P-#{i + 1}") do |ch, num| Producer.new(ch, num).run end } consumers = 3.times.map { |i| Ractor.new(channel, name: "C-#{i + 1}") do |ch| Consumer.new(ch).run end } producers.each(&:take) consumers.each(&:take) ֤3BDUPSͷ࣮ߦΛ଴ͪ߹ΘͤΔ Ҿ਺ͱ֤ͯ͠3BDUPSͷ໊લͱ $IBOOFMͱ࠾൪ػΛ౉͢ Ҿ਺ͱ֤ͯ͠3BDUPSͷ໊લͱ $IBOOFMΛ౉͢

Slide 41

Slide 41 text

1SPEVDFSΫϥεͷ࣮૷ class Producer def initialize(channel, numbering) @channel = channel @numbering = numbering end def run # … end private def issue_product_no # … end end # Channel Ractor # ࠾൪ػ3BDUPS QSPEVDU൪߸Λൃߦ͢ΔͨΊͷϝιου

Slide 42

Slide 42 text

class Producer def initialize(channel, numbering) # … def run loop do product_no = issue_product_no # … end end private def issue_product_no @numbering.send Ractor.current # … end end 3BDUPSTFOE ⾩SFDFJWF ର৅ͷ3BDUPSΦϒδΣΫτ΁ ϝοηʔδΛૹΔ ࠾൪ػʹ͜ͷ3BDUPSࣗ਎ΛૹΔ 1SPEVDFSΫϥεͷ࣮૷ SVOJTTVF@QSPEVDU@OPϝιου

Slide 43

Slide 43 text

ϝΠϯϓϩάϥϜͷ࣮૷ ࠾൪ػ3BDUPS numbering = Ractor.new(no = 0) do |no| loop do no += 1 producer = Ractor.receive producer.send no end end ड͚औͬͨ1SPEVDFS3BDUPSʹQSPEVDU൪߸Λฦૹ͢Δ 1SPEVDFS3BDUPSΛड͚औΔ 3BDUPSSFDFJWF ⾩TFOE ࣗ਎ͷJODPNJOHQPSU͔Β ϝοηʔδΛड͚ೖΕΔ QSPEVDU൪߸ΛΧ΢ϯτΞοϓ͢Δ

Slide 44

Slide 44 text

1SPEVDFSΫϥεͷ࣮૷ SVOJTTVF@QSPEVDU@OPϝιου class Producer def initialize(channel, numbering) # … def run loop do product_no = issue_product_no # … end end private def issue_product_no @numbering.send Ractor.current Ractor.receive end end ࠾൪ػ͔Βड͚औͬͨQSPEVDU൪߸Λฦ͢

Slide 45

Slide 45 text

class Producer def initialize(channel, numbering) # … def run loop do product_no = issue_product_no @channel.send ["Product no. #{product_no}”, Ractor.current] end end private def issue_product_no @numbering.send Ractor.current Ractor.receive end end ࠾൪ͨ͠QSPEVDUͱɺ͜ͷ3BDUPSࣗ਎Λ$IBOOFMʹૹΔ 1SPEVDFSΫϥεͷ࣮૷ SVOJTTVF@QSPEVDU@OPϝιου

Slide 46

Slide 46 text

ϝΠϯϓϩάϥϜͷ࣮૷ $IBOOFM3BDUPS channel = Ractor.new do loop do product, producer = Ractor.receive puts “#{producer.name} produces #{product}." Ractor.yield product end end 3BDUPSZJFME ⾩UBLF ࣗ਎ͷPVUHPJOHQPSU͔Β ϝοηʔδΛૹΓग़͢ 1SPEVDFS3BDUPS͔ΒσʔλΛड͚औͬͯ ͦͷ··$POTVNFS3BDUPS΁ૹΓग़͚ͩ͢ʂ QSPEVDUΛૹΓग़͢ QSPEVDUΛड͚औΔ

Slide 47

Slide 47 text

$POTVNFSΫϥεͷ࣮૷ class Consumer def initialize(channel) @channel = channel end def run loop do product = @channel.take puts "#{Ractor.current.name} consumes #{product}" end end end 3BDUPSUBLF ⾩ZJFME ର৅ͷ3BDUPSΦϒδΣΫτ͔Β ϝοηʔδΛҾ͖ग़͢ # Channel Ractor $IBOOFM͔ΒૹΓग़͞ΕͨQSPEVDUΛड͚औΔ

Slide 48

Slide 48 text

$POTVNFSΫϥεͷ࣮૷ class Consumer def initialize(channel) @channel = channel end def run loop do product = @channel.take puts "#{Ractor.current.name} consumes #{product}" end end end 3BDUPSUBLF ⾩ZJFME ର৅ͷ3BDUPSΦϒδΣΫτ͔Β ϝοηʔδΛҾ͖ग़͢ ׬੒ʂ # Channel Ractor $IBOOFM͔ΒૹΓग़͞ΕͨQSPEVDUΛड͚औΔ

Slide 49

Slide 49 text

3BDUPSΛ࢖࣮ͬͨ૷ͷͨͷ͍͠ͱ͜Ζ ✔ొ৔ਓ෺͸3BDUPS͚ͩͳͷͰΒ͘Β࣮͘૷Ͱ͖Δ ✔ϧʔϧ͕γϯϓϧͳͷͰΒ͘Β࣮͘૷Ͱ͖Δ ʮ3BDUPS͸3BDUPS͔ΒϝοηʔδΛͻͱͭड͚औΔ ʮ3BDUPS͸3BDUPS΁ϝοηʔδΛͻͱͭૹΔʯ ڝ߹͕ൃੜ͠ͳ͍ $IBOOFM͕ঢ়ଶΛ࣋ͨͳ͍ ✔3BDUPSಉ࢜Λ૊Έ߹Θͤͯ ϓϩάϥϜΛߟ͑Δͷ͕ͨͷ͍͠ʂ ‎

Slide 50

Slide 50 text

3BDUPSΛ࢖࣮ͬͨ૷ͷͨͷ͍͠ͱ͜Ζ ✔ొ৔ਓ෺͸3BDUPS͚ͩͳͷͰΒ͘Β࣮͘૷Ͱ͖Δ ✔ϧʔϧ͕γϯϓϧͳͷͰΒ͘Β࣮͘૷Ͱ͖Δ ʮ3BDUPS͸3BDUPS͔ΒϝοηʔδΛͻͱͭड͚औΔ ʮ3BDUPS͸3BDUPS΁ϝοηʔδΛͻͱͭૹΔʯ ڝ߹͕ൃੜ͠ͳ͍ $IBOOFM͕ঢ়ଶΛ࣋ͨͳ͍ ✔3BDUPSಉ࢜Λ૊Έ߹Θͤͯ ϓϩάϥϜΛߟ͑Δͷ͕ͨͷ͍͠ʂ ॏཁ ‎

Slide 51

Slide 51 text

͓ർΕ༷Ͱͨ͠

Slide 52

Slide 52 text

༨ஊ ࡢ೥य़ɺ3VCZ͞Έͬͱʹͯ

Slide 53

Slide 53 text

༨ஊ ࡢ೥य़ɺ3VCZ͞Έͬͱʹͯ

Slide 54

Slide 54 text

෬ઢճऩEPOF Ұ೥ӽ͠Ͱ ༨ஊ ࡢ೥य़ɺ3VCZ͞Έͬͱʹͯ

Slide 55

Slide 55 text

·ͱΊ 3BDUPSͰ ฒߦฒྻϓϩάϥϛϯάΛ Β͘Βͨ͘ͷ͠ΜͰ͍͖·͠ΐ͏ʂ

Slide 56

Slide 56 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠