ã¢ã¯ã¿ã¼ã¢ãã«
Erlang Land
ãèªãã§Erlangãå¦ãã ã
Erlangã®ä¸¦åå¦çãå¦ã¶ãã¨ã§ã¢ã¯ã¿ã¼ã¢ãã«ã®ç解ãã§ããï¼
æ¦å¿µçã«ç解ã§ãã¦ãªãã£ãScalaã®Actorã©ã¤ãã©ãªãèªã¿æ¸ããã§ããããã«ãªãã¾ããã
Erlangã®ä¸¦åçãã£ãããããScalaã§æ¸ãã¦ã¿ã¾ããã
import scala.actors._ class FibActor(var name:String) extends Actor { def act = { receive { case i:Int => println(name + ": " + fib(i)) } } def fib(n:Int):Int = { n match { case 0 => 1 case 1 => 1 case _ => fib(n - 1) + fib(n - 2) } } } object ActorTest { def main(arg:Array[String]) = { var l = List(40,5,10,20,42,41,30) for (n <- l) { var f = new FibActor("fib[" + n + "]") f.start f ! n } } }
DualCoreçã®å ´åã«ãããå®è¡ãã¦CPU使ç¨çãçºãã¦ããã¨ã並åå¦çããã¦ãããã¨ããããããã¾ãã
åä½
var f = new FibActor("fib[" + n + "]") f.start
ããã§ããã»ã¹ãçæãããactã¡ã½ããå ã«ããããã«receiveç¶æ ã«ãªãï¼ã¡ãã»ã¼ã¸ãéããã¦ããã®ãç£è¦ï¼
f ! n
ããã§çæãããããã»ã¹ãfãã«å¯¾ãã¦ãnãã¨ããã¡ãã»ã¼ã¸ãéã
receive { case i:Int => println(name + ": " + fib(i)) }
ããã¦ããã»ã¹ãfãã¯receiveãã¦éããããnãããã¨ã«ãã£ããããæ°åãè¨ç®ãåºåãã¾ã
Threadã¨éã£ã¦ã¡ã¢ãªãå
±æãããã¡ãã»ã¼ã¸ã®éåä¿¡ã§åä½ããçºãããªãç°¡åãªæãã§ã
ããã¼ããããã
Scalaã«ã¯ç°¡åã«actorãå®è£
ã§ããactorãããã¯ããã£ãããä»ã«ãé¢é£ã©ã¤ãã©ãªãããã®ã§
æ¢ã£ã¦ã¿ããã¨æãã¾ãã
ãããã並åå¦çã¯Erlangã®ã»ããæ´ç·´ããã¦ããå°è±¡ã§ããã