lispとrubyとpythonと その7 継続とFiberの続き(ruby)
継続ってスタックをどっかに保存しとくんだろうけど、じゃあ別スレッドの継続ってどうなるんだろ、と思って実験。
RuntimeError: continuation called across threads
だって。
require 'continuation' puts "\n" $c1 = nil def test0(arg) printf "test0 begin %s\n" ,arg test1 arg printf "test0 end %s\n" ,arg end def test1(arg) printf "\ttest1 begin %s\n" ,arg test2 arg printf "\ttest1 end %s\n" ,arg end def test2(arg) printf "\t\ttest2 begin %s\n" ,arg callcc do |c| $c1 = c end printf "\t\ttest2 end %s\n" ,arg end t = Thread.new do Thread.pass test0 "tset" end t.join flg = nil if !flg flg = !flg $c1.call end #->test0 begin tset # test1 begin tset # test2 begin tset # test2 end tset # test1 end tset # test0 end tset # RuntimeError: continuation called across threads