diff options
author | Philipp Haller <hallerp@gmail.com> | 2007-02-02 15:15:44 +0000 |
---|---|---|
committer | Philipp Haller <hallerp@gmail.com> | 2007-02-02 15:15:44 +0000 |
commit | 8c1bbafee4c68ccd158786deb4643d5a3074ce0d (patch) | |
tree | a61eeeae54610131b88218b82beda5b67f1d817d /docs/examples/actors/BoundedBufferTest.scala | |
parent | 07c368dcdfe75376c4af87829e653c9c6064a117 (diff) | |
download | scala-8c1bbafee4c68ccd158786deb4643d5a3074ce0d.tar.gz scala-8c1bbafee4c68ccd158786deb4643d5a3074ce0d.tar.bz2 scala-8c1bbafee4c68ccd158786deb4643d5a3074ce0d.zip |
Diffstat (limited to 'docs/examples/actors/BoundedBufferTest.scala')
-rw-r--r-- | docs/examples/actors/BoundedBufferTest.scala | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/docs/examples/actors/BoundedBufferTest.scala b/docs/examples/actors/BoundedBufferTest.scala index 5a04f7aafd..7585d8779a 100644 --- a/docs/examples/actors/BoundedBufferTest.scala +++ b/docs/examples/actors/BoundedBufferTest.scala @@ -2,29 +2,29 @@ package examples.actors import scala.actors.Actor._ -class BoundedBuffer[T](N: int) { - private case class Get - private case class Put(x: T) +object boundedbuffer { + class BoundedBuffer[T](N: int) { + private case class Get + private case class Put(x: T) - private val buffer = actor { - val buf = new Array[T](N) - var in = 0; var out = 0; var n = 0 - while(true) { - receive { - case Put(x) if n < N => - buf(in) = x; in = (in + 1) % N; n = n + 1; reply() - case Get() if n > 0 => - val r = buf(out); out = (out + 1) % N; n = n - 1; reply(r) + private val buffer = actor { + val buf = new Array[T](N) + var in = 0; var out = 0; var n = 0 + while(true) { + receive { + case Put(x) if n < N => + buf(in) = x; in = (in + 1) % N; n = n + 1; reply() + case Get() if n > 0 => + val r = buf(out); out = (out + 1) % N; n = n - 1; reply(r) + } } } - } - def put(x: T): Unit = buffer !? Put(x) + def put(x: T): Unit = buffer !? Put(x) - def get: T = (buffer !? Get()).asInstanceOf[T] -} + def get: T = (buffer !? Get()).asInstanceOf[T] + } -object BoundedBufferTest { def main(args: Array[String]) = { val buf = new BoundedBuffer[Int](1) buf.put(42) |