diff options
author | michelou <michelou@epfl.ch> | 2009-06-16 10:49:14 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2009-06-16 10:49:14 +0000 |
commit | 53ed9b920e738e784289548d7cc90e8e2dcd0124 (patch) | |
tree | 9c6f7ef79cdc127c77c4105ef63a44833870d707 /docs/examples/pilib/twoPlaceBuffer.scala | |
parent | a4bdfdcccb498aeec2511f9230647ec27da6ff41 (diff) | |
download | scala-53ed9b920e738e784289548d7cc90e8e2dcd0124.tar.gz scala-53ed9b920e738e784289548d7cc90e8e2dcd0124.tar.bz2 scala-53ed9b920e738e784289548d7cc90e8e2dcd0124.zip |
added headers, svn keywords, updated pilib exam...
added headers, svn keywords, updated pilib examples
Diffstat (limited to 'docs/examples/pilib/twoPlaceBuffer.scala')
-rw-r--r-- | docs/examples/pilib/twoPlaceBuffer.scala | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/docs/examples/pilib/twoPlaceBuffer.scala b/docs/examples/pilib/twoPlaceBuffer.scala index 020f3e4992..f0f278317a 100644 --- a/docs/examples/pilib/twoPlaceBuffer.scala +++ b/docs/examples/pilib/twoPlaceBuffer.scala @@ -8,18 +8,18 @@ object twoPlaceBuffer extends Application { /** * Specification. */ - def Spec[a](in: Chan[a], out: Chan[a]): Unit = { + def Spec[A](in: Chan[A], out: Chan[A]) { - def B0: unit = choice ( + def B0: Unit = choice ( in * (x => B1(x)) ) - def B1(x: a): unit = choice ( + def B1(x: A): Unit = choice ( out(x) * (B0), in * (y => B2(x, y)) ) - def B2(x: a, y: a): unit = choice ( + def B2(x: A, y: A): Unit = choice ( out(x) * (B1(y)) ) @@ -29,38 +29,38 @@ object twoPlaceBuffer extends Application { /** * Implementation using two one-place buffers. */ - def Impl[a](in: Chan[a], out: Chan[a]): unit = { + def Impl[A](in: Chan[A], out: Chan[A]) { ///- ... complete here ... // one-place buffer - def OnePlaceBuffer[a](in: Chan[a], out: Chan[a]): Unit = { - def B0: unit = choice ( in * (x => B1(x)) ) - def B1(x: a): unit = choice ( out(x) * (B0)) + def OnePlaceBuffer[A](in: Chan[A], out: Chan[A]) { + def B0: Unit = choice ( in * (x => B1(x)) ) + def B1(x: A): Unit = choice ( out(x) * (B0)) B0 } - val hidden = new Chan[a] + val hidden = new Chan[A] spawn < OnePlaceBuffer(in, hidden) | OnePlaceBuffer(hidden, out) > ///+ } - val random = new java.util.Random() + val random = new util.Random() - def Producer(n: Int, in: Chan[String]): Unit = { + def Producer(n: Int, in: Chan[String]) { Thread.sleep(random.nextInt(1000)) val msg = "" + n choice (in(msg) * {}) Producer(n + 1, in) } - def Consumer(out: Chan[String]): unit = { - Thread.sleep(random.nextInt(1000)); - choice (out * { msg => () }); + def Consumer(out: Chan[String]) { + Thread.sleep(random.nextInt(1000)) + choice (out * { msg => () }) Consumer(out) } val in = new Chan[String] - in.attach(s => System.out.println("put " + s)) + in.attach(s => println("put " + s)) val out = new Chan[String] - out.attach(s => System.out.println("get " + s)) + out.attach(s => println("get " + s)) //spawn < Producer(0, in) | Consumer(out) | Spec(in, out) > spawn < Producer(0, in) | Consumer(out) | Impl(in, out) > |