2
** ________ ___ / / ___ Scala API **
3
** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
4
** __\ \/ /__/ __ |/ /__/ __ | **
5
** /____/\___/_/ |_/____/_/ | | **
9
package examples.jolib;
11
import concurrent.SyncVar;
12
import concurrent.jolib._;
14
class Ref[a](init: a) extends Join {
16
object get extends Synchr[a](this) { case class C() extends SyncVar[a]; }
17
object set extends Synchr[unit](this) { case class C(x: a) extends SyncVar[unit]; }
18
object state extends Asynchr(this) { case class C(x: a); }
21
Pair(List(get, state), { case List(g @ get.C(), state.C(x) ) =>
22
{ g.set(x); state(state.C(x)) } }),
23
Pair(List(set, state), { case List(s @ set.C(x), state.C(y) ) =>
24
{ s.set(()); state(state.C(x)) } })
29
def Get: a = get(get.C());
30
def Set(x: a): unit = set(set.C(x));
35
def main(args: Array[String]) = {
36
System.out.println("Started.");
38
concurrent.ops.spawn({
40
System.out.println("Reference r1 created.");
41
System.out.println("Value r1 (first time) = " + r1.Get);
43
System.out.println("Value r1 (second time) = " + r1.Get);
45
concurrent.ops.spawn({
46
val r2 = new Ref(100);
47
System.out.println("Reference r2 created.");
48
System.out.println("Value r2 (first time) = " + r2.Get);
50
System.out.println("Value r2 (second time) = " + r2.Get);