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

re: rinda 2017

re: rinda 2017

Nagoya Ruby Kaigi 2017

seki at druby.org

February 11, 2017
Tweet

More Decks by seki at druby.org

Other Decks in Programming

Transcript

  1. more slide sponsors ս&YDFMך侔䋒㔳דفٗحزחٓكٕվ知⽃חאֽ׋ְ̤搀俱דֲתְװ׶倯䊴 ׃♳־תׅ̤➙ּׅ!BXB[FLJחչ׉׸妜׃٦պה%.׃״ֲ劍꟦ꣲ㹀 !BXB[FLJ Ⰻ鿇׌׏ה䙼׏ג׋??![[BL@KQ E3VCZח״׷ⴓ侔٥8FCفؚٗٓىؚٝ ؔ٦ي爡F#PPL4UPSF IUUQ

    FTUPSFPINTIBDPKQUJUMFT1!IJTBTIJN ׫זׁתծTFLJ眍׾ֶ嚂׃׫ֻ׌ְׁկ䊛䃵歲꥔ך倯כծLBXBTBLJSCծZPLPIBNBSC׾ ֶ鑐׃ֻ׌ְׁկ,ذٖؽך飑ⰅכծTFLJׁ׿穗歋ד׀湱锑ְ׋׌ֽ׷ה׀⼿⸂׃תׅկ!UTVCPJ ִ׬ׁ׿ծֶ׭דהֲֻׁ׵ְֻ׿׮ֶ׭דהֲ!WFTUJHF@ GSPHPSH叶加דأٗ٦٥ؽآطأ׃גְתׅկ!EFO .JTPDBך؟٦ؽأ׾葺ֻ׃גְֻ⟗꟦׾Ⰻ㕂ַ׵⹫꧊׃גתׅ ٌٔ٦ز⹶⹡〳  SFDSVJUNJTPDBKQ!TFJLZV@NJTPDB
  2. νʔϜΛ੒௕ͤ͞ΔϦʔμʔγοϓ ࣗݾ૊৫ԽνʔϜͷҭͯํ 3PZ0TIFSPWF衼  䃊歊嵞✳鏬ջث٦ي׾䧭ꞿׇׁ׷ٔ٦ت٦ءحف荈䊹 穈籼⻉ث٦يך肪ג倯⟎ռؔٓ؎ٔ٦٥آٍػٝ 䎃僰갦ⴚ遤✮㹀  չ"SUPG6OJU5FTUJOHպזוך衼罏ה׃ג濼׵׸׷3PZ0TIFSPWFך倜ⴚչ&MBTUJD-FBEFSTIJQ (SPXJOHTFMGPSHBOJ[JOHUFBNTպ窫额缺鏬⚥דׅկث٦ي׾荈䊹穈籼⻉ח㼪ֻ׋׭ךٔ٦

    ت٦ءحفך֮׶倯׾瘗罏ך穗꿀ח㛇בְגٌرٕ⻉׃ג铡僇׃׋⵸⼱הծչ։ָ濼׷ץ ֹךֿהպךث٦ئ٦ت٦晛ך״ֲזؒحإ؎꧊ַ׵ז׷鿇圓䧭ך剅硂דծ傈劤铂 晛חכㅡׁ׿׾כׄ׭韜螟㛁瘗ꤏח״׷չاؿزؐؑ،Ꟛ涪ךث٦ئ٦ت٦ָ濼׷ץֹ ֿהպָאֹתׅ 傈劤铂晛ؒحإ؎㛁瘗ꤏ✮㹀❁⾱姻⽆ׁ׿ծ嵲ꅿ 䒽䧭ׁ׿ծ䀤䃊䎊歑ׁ׿ծ吐卌⨳㣕龤ׁ׿ծ䎤぀㎖籼ׁ ׿ծꟼ㼛⤥ׁ׿ծ䎂ꑚ⨳⯢ׁ׿ծ宕戭繟珷ׁ׿ծし纷륊 㣕龤ׁ׿BOENPSF וֲ׊׀劍䖉ֻ׌ְׁ 铣׫♳־׷ך㣐㢌זךד荈ⴓד铣׿די
  3. ໊લʹΑͬͯΞΫηε ׾㹀纏׃׋ؔـآؙؑز縧ֻ ⦼ָ㢌׻׷תד䖉א module Rinda class Njet def initialize(value) @value

    = value end def ===(other) @value != other end end end ts.read(['nagoya', Rinda::Njet.new(3)])
  4. ετϦʔϜ UBJMةفٕה銲稆ךةفٕד圓䧭ׅ׷⢽ UBJM׾鹌׭ծ銲稆׾鷄⸇ ['stream', 'tail', 2] ['stream', 1, 'hello'] ['stream',

    2, 'world'] _, _, index = ts.take(['stream', 'tail', nil]) index += 1 ts.write(['stream', 'tail', index] ts.write(['stream', index, new_value])
  5. ݮΔετϦʔϜ IFBEةفٕ׾⢪ֲ IFBEةفٕ׾鹌׭ծ銲稆׾⵴ꤐ ['stream', 'head', 1] ['stream', 1, 'hello'] ['stream',

    2, 'world'] _, _, index = ts.take(['stream', 'head', nil]) ts.take(['stream', index, nil]) index += 1 ts.write(['stream', 'head', index]
  6. Thread 鎘皾חDPSF׾銲実׃זְז׵5ISFBEד״ְ ֶ䩛鯪 ts = Rinda::TupleSpace.new ts.write(['fact', 1, 1]) (2..6).each

    do |x| Thread.new(x) do |n| _, _, prev = ts.read(['fact', n - 1, nil]) ts.write(['fact', x, prev * x]) end end p ts.read(['fact', 6, nil])
  7. Thread 鎘皾חDPSF׾銲実׃זְז׵5ISFBEד״ְ ֶ䩛鯪 ts = Rinda::TupleSpace.new ts.write(['fact', 1, 1]) (2..6).each

    do |x| Thread.new(x) do |n| _, _, prev = ts.read(['fact', n - 1, nil]) ts.write(['fact', x, prev * x]) end end p ts.read(['fact', 6, nil])
  8. ҉هͯ͠ module Rinda module_function def rinda_eval(ts) ts = DRbObject.new(ts) unless

    DRbObject === ts pid = fork do Thread.current['DRb'] = nil DRb.stop_service DRb.start_service place = TupleSpaceProxy.new(ts) tuple = yield(place) place.write(tuple) rescue nil end Process.detach(pid) end end
  9. ҉هͯ͠ module Rinda module_function def rinda_eval(ts) ts = DRbObject.new(ts) unless

    DRbObject === ts pid = fork do Thread.current['DRb'] = nil DRb.stop_service DRb.start_service place = TupleSpaceProxy.new(ts) tuple = yield(place) place.write(tuple) rescue nil end Process.detach(pid) end end TupleSpaceͷproxyΛ࡞ΓɺforkݩͷdRubyΛऴΘΒͤͯɺࣗ෼ͷ෼ ͷdRubyΛىಈ͢Δɻ yieldͨ͠໭Γ஋Λwriteͯ͠ऴΘΓ
  10. Rinda::rinda_eval require 'rinda/tuplespace' require 'rinda/eval' DRb.start_service ts = Rinda::TupleSpace.new ts.write(['fact',

    1, 1]) (2..6).each do |x| Rinda::rinda_eval(ts) do |place| _, _, prev = place.read(['fact', x - 1, nil]) ['fact', x, prev * x] end end p ts.read(['fact', 6, nil])
  11. Rinda::rinda_eval require 'rinda/tuplespace' require 'rinda/eval' DRb.start_service ts = Rinda::TupleSpace.new ts.write(['fact',

    1, 1]) (2..6).each do |x| Rinda::rinda_eval(ts) do |place| _, _, prev = place.read(['fact', x - 1, nil]) ['fact', x, prev * x] end end p ts.read(['fact', 6, nil])
  12. Rinda::rinda_eval require 'rinda/tuplespace' require 'rinda/eval' DRb.start_service ts = Rinda::TupleSpace.new ts.write(['fact',

    1, 1]) (2..6).each do |x| Rinda::rinda_eval(ts) do |place| _, _, prev = place.read(['fact', x - 1, nil]) ['fact', x, prev * x] end end p ts.read(['fact', 6, nil]) ɹ֊৐ΛٻΊΔϓϩάϥϜ λωʹͳΔλϓϧΛ͓͖ɺ nͷ֊৐ΛٻΊΔϓϩηεΛevalͰ࡞Γ·͢ n-1ͷ݁ՌΛread͠ɺ৐ͨ݁͡ՌΛwrite͠·͢ ʢಛʹ଎͘ͳ͍Ͱ͢ʣ