diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-09 11:06:22 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-12-09 17:11:05 -0800 |
commit | e55510607031aaf7b8473453f83c44a26c9b97e0 (patch) | |
tree | 987d4aeeef387ed435acc64ffadfdf78e6f65bce /docs/examples/pilib/semaphore.scala | |
parent | dc6dd58d9da441b591580684f3d2f38d7898e7d4 (diff) | |
download | scala-e55510607031aaf7b8473453f83c44a26c9b97e0.tar.gz scala-e55510607031aaf7b8473453f83c44a26c9b97e0.tar.bz2 scala-e55510607031aaf7b8473453f83c44a26c9b97e0.zip |
Remove docs/examples; they reside at scala/scala-dist
Diffstat (limited to 'docs/examples/pilib/semaphore.scala')
-rw-r--r-- | docs/examples/pilib/semaphore.scala | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/docs/examples/pilib/semaphore.scala b/docs/examples/pilib/semaphore.scala deleted file mode 100644 index 951c90e8d4..0000000000 --- a/docs/examples/pilib/semaphore.scala +++ /dev/null @@ -1,72 +0,0 @@ -package examples.pilib - -import scala.concurrent.pilib._ - -/** Solution of exercise session 6 (first question). */ -object semaphore { - - class Signal extends Chan[Unit] { - def send = write(()) - def receive = read - } - - /** Interface. */ - trait Semaphore { - def get: Unit - def release: Unit - } - - /** First implementation. */ - class Sem1 extends Semaphore { - - private val g = new Signal - private val r = new Signal - - def get: Unit = g.send - def release: Unit = r.send - - private def Sched: Unit = choice ( - g * (x => { r.receive; Sched }), - r * (x => Sched) - ) - spawn< Sched > - } - - /** Second implementation. */ - class Sem2 extends Semaphore { - - private val a = new Signal - private val na = new Signal - - def get { a.receive; spawn< na.send > } - def release: Unit = choice ( - a * (x => spawn< a.send >), - na * (x => spawn< a.send >) - ) - spawn< a.send > - } - - /** Test program. */ - def main(args: Array[String]) { - val random = new util.Random() - val sem = new Sem2 - def mutex(p: => Unit) { sem.get; p; sem.release } - - spawn< { - Thread.sleep(1 + random.nextInt(100)); - mutex( { - println("a1"); - Thread.sleep(1 + random.nextInt(100)); - println("a2") - } ) - } | { - Thread.sleep(1 + random.nextInt(100)); - mutex( { - println("b1"); - Thread.sleep(1 + random.nextInt(100)); - println("b2") - } ) - } >; - } -} - |