diff options
author | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
---|---|---|
committer | Hubert Plociniczak <hubert.plociniczak@epfl.ch> | 2011-11-02 14:34:35 +0000 |
commit | b6778be91900b8161e705dc2598ef7af86842b0b (patch) | |
tree | d15e8ec18a37eec212f50f1ace27714d7e7d4d34 /test/pending/shootout/message.scala | |
parent | ac6c76f26d884a94d0c9ff54f055d3f9ab750bac (diff) | |
download | scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.gz scala-b6778be91900b8161e705dc2598ef7af86842b0b.tar.bz2 scala-b6778be91900b8161e705dc2598ef7af86842b0b.zip |
Begone t1737...
Diffstat (limited to 'test/pending/shootout/message.scala')
-rw-r--r-- | test/pending/shootout/message.scala | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/pending/shootout/message.scala b/test/pending/shootout/message.scala new file mode 100644 index 0000000000..a7a1dacc9d --- /dev/null +++ b/test/pending/shootout/message.scala @@ -0,0 +1,47 @@ +/* The Computer Language Shootout + http://shootout.alioth.debian.org/ + contributed by Isaac Gouy +*/ + + +import scala.concurrent._ + +object message { + def main(args: Array[String]) = { + val n = Integer.parseInt(args(0)) + val nActors = 500 + val finalSum = n * nActors + + case class Message(value: Int) + + class Incrementor(next: Pid) extends Actor { + var sum = 0 + + override def run() = { + while (true) { + receive { + case Message(value) => + val j = value + 1 + if (null != next){ + next ! Message(j) + } else { + sum = sum + j + if (sum >= finalSum){ + Console.println(sum); + System.exit(0) // exit without cleaning up + } + } + } + } + } + + def pid() = { this.start; this.self } + } + + def actorChain(i: Int, a: Pid): Pid = + if (i > 0) actorChain(i-1, new Incrementor(a).pid ) else a + + val firstActor = actorChain(nActors, null) + var i = n; while (i > 0){ firstActor ! Message(0); i = i-1 } + } +} |